Open In App

Linux Post-Installation Steps for Docker Engine

Last Updated : 18 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

When it comes to containerization Docker is the go to choice allowing developers and system admins to bundle applications and their requirements into containers. After setting up Docker Engine on your Linux setup it's essential to carry out installation tasks to make the most of its capabilities. Let's explore these steps for effective Docker usage.

Terminologies

  • Docker Engine: The program that sets up and oversees containers, on your computer system.
  • Container: A self-contained package containing an application and all the necessary components ensuring separation and flexibility.
  • Docker Image: A blueprint utilized to generate containers.
  • Docker Registry: A storage space for keeping and sharing Docker images.
  • Docker Compose: A utility, for outlining and executing Docker applications with containers.

Post-Installation Steps

After setting up Docker Engine on your Linux system there are some tasks you need to do to ensure that Docker runs smoothly securely and efficiently. Lets take a look, at these steps that will help you make the most of Docker while following industry standards.

Why Post-Installation Setup Matters

It's essential to configure Docker after installation for the following reasons;

  • Enhanced Security: By managing Docker as a root user and setting up access controls correctly you can reduce security vulnerabilities.
  • Improved Efficiency: Making sure that Docker starts automatically when your system boots up ensures it's always ready for your container-based workflows.
  • Better User Experience: Simplifying how you manage Docker leads to acontainer-based productive development or operational environment.

Manage Docker as a Non-root User (Recommended)

The Docker daemon connects to a Unix socket of a TCP port. By default the Unix socket is owned by the root user and other users need to use sudo to access it. The Docker daemon always operates under the root user.

To avoid having to use sudo before the docker command you can set up a Unix group named docker and add users to it. When the Docker daemon starts it establishes a Unix socket that can be accessed by members of the docker group. Some Linux distributions automatically create this group when Docker Engine is installed using a package manager. In cases there's no need for you to manually create the group.

Why Add a User to the Docker Group?

By default in Docker commands you need to have root privileges which's risky in terms of security because if theres a misconfiguration or vulnerability, in a Docker container it could put your whole system at risk so by adding your user to the Docker group you can run Docker commands without needing sudo which follows the principle of least privilege and helps lower security risks.
To create the docker group and add the user:

1. Create the docker group

sudo groupadd docker-geek

In my case its already existed

2. Add the user to the docker group

sudo usermod -aG docker-geek $USER

When using the usermod command with the -a option you are essentially. Appending a user to a group. It's important to pair this with the -G option, which indicates the group the user belongs to. The use of $USER suggests that we are referring to the logged in root user. If dealing with a user who is not logged in it becomes necessary to state their username.

3.Run the following command to activate the changes to groups

newgrp docker-geek

4.Verify that you have the non-root access

docker run hello-world

docker run hello-world

Enabling Docker to Start on Boot

Ensuring that Docker starts automatically when your system boots up makes it easily accessible whenever you require it which helps to streamline your work processes.

Enable the Docker Service by following command:

sudo systemctl enable docker.service

sudo systemctl enable containerd.service

To prevent this action opt for "disable" instead.

sudo systemctl disable docker.service

sudo systemctl disable containerd.service

Managing Docker Services with systemd:

To start, stop, or restart the Docker service:

sudo systemctl start docker

sudo systemctl stop docker

sudo systemctl restart docker

Best practices for managing Docker service on Linux systems

Managing Resources: It's essential to set resource limits (such as CPU and memory) for Docker containers in production settings. This helps avoid conflicts over resources and maintains the performance on the host system.

Stay Up to Date: Make sure to keep your Docker Engine updated regularly. This way you can take advantage of the security updates bug fixes and performance improvements available.

Other Essential Post-Installation Steps

Verify Docker Installation

Check if Docker Engine is running correctly:

docker version

docker version

Testing Docker Installation and Troubleshooting

Run a simple "Hello World" container to test basic functionality:

docker run hello-world

docker run hello-world

Pull Images from Docker Hub

  • Docker Hub is the default public registry. Search for and pull images you need:

docker pull ubuntu:latest

Run Containers

  • Create and start a container from an image:

docker run -it ubuntu:latest /bin/bash

This command launches an interactive Ubuntu container and provides a bash shell within it.

Manage Containers

  • List running containers:

docker ps

Screenshot-2024-08-24-013130

Stop a container

docker stop <container_id_or_name>

Screenshot-2024-08-24-014537

Remove a container

docker rm <container_id_or_name>

Screenshot-2024-08-24-014651

Example

If you're looking to set up a Nginx web server using a Docker container:

Pull the Nginx image:

docker pull nginx:latest

Screenshot-2024-08-24-012558

Run the Nginx container

docker run -d -p 80:80 --name my-web-server nginx:latest

Screenshot-2024-08-24-013317

This command:

  • Run the container in detached mode using the command ( d).
  • Map port 80 of the container to port 80 of the host with the flag ( p 80;80).
  • Assign the name "my web server" to the container.

Now open your web browser. Go to http;//localhost. You will come across the Nginx welcome page.

my web server

Common post-installation issues and how to resolve them

Having trouble connecting to the Docker daemon? Make sure that the Docker service is up and running by checking its status with "sudo systemctl status docker." If its not running already you can start it by using the command "sudo systemctl start docker."

Sorry there seems to be an issue with accessing permissions, in Docker settings, which can be resolved by ensuring your user is added to the Docker group and logging out and back in to make the changes active again.

Having trouble pulling images? Make sure your internet connection is double check that you've got the right image name and tag selected.


Next Article
Article Tags :

Similar Reads