Linux post-installation steps for Docker Engine (2024)

These optional post-installation procedures describe how to configure yourLinux host machine to work better with Docker.

The Docker daemon binds to a Unix socket, not a TCP port. By default it's theroot user that owns the Unix socket, and other users can only access it usingsudo. The Docker daemon always runs as the root user.

If you don't want to preface the docker command with sudo, create a Unixgroup called docker and add users to it. When the Docker daemon starts, itcreates a Unix socket accessible by members of the docker group. On some Linuxdistributions, the system automatically creates this group when installingDocker Engine using a package manager. In that case, there is no need for you tomanually create the group.

Warning

The docker group grants root-level privileges to the user. Fordetails on how this impacts security in your system, seeDocker Daemon Attack Surface.

Note

To run Docker without root privileges, seeRun the Docker daemon as a non-root user (Rootless mode).

To create the docker group and add your user:

  1. Create the docker group.

  2. Add your user to the docker group.

    $ sudo usermod -aG docker $USER
  3. Log out and log back in so that your group membership is re-evaluated.

    If you're running Linux in a virtual machine, it may be necessary torestart the virtual machine for changes to take effect.

    You can also run the following command to activate the changes to groups:

    $ newgrp docker
  4. Verify that you can run docker commands without sudo.

    $ docker run hello-world

    This command downloads a test image and runs it in a container. When thecontainer runs, it prints a message and exits.

    If you initially ran Docker CLI commands using sudo before adding your userto the docker group, you may see the following error:

    WARNING: Error loading config file: /home/user/.docker/config.json -stat /home/user/.docker/config.json: permission denied

    This error indicates that the permission settings for the ~/.docker/directory are incorrect, due to having used the sudo command earlier.

    To fix this problem, either remove the ~/.docker/ directory (it's recreatedautomatically, but any custom settings are lost), or change its ownership andpermissions using the following commands:

    $ sudo chown "$USER":"$USER" /home/"$USER"/.docker -R$ sudo chmod g+rwx "$HOME/.docker" -R

Configure Docker to start on boot with systemd

Many modern Linux distributions usesystemd tomanage which services start when the system boots. On Debian and Ubuntu, theDocker service starts on boot by default. To automatically start Docker andcontainerd on boot for other Linux distributions using systemd, run thefollowing commands:

$ sudo systemctl enable docker.service$ sudo systemctl enable containerd.service

To stop this behavior, use disable instead.

$ sudo systemctl disable docker.service$ sudo systemctl disable containerd.service

If you need to add an HTTP proxy, set a different directory or partition for theDocker runtime files, or make other customizations, seecustomize your systemd Docker daemon options.

Docker provides logging drivers forcollecting and viewing log data from all containers running on a host. Thedefault logging driver, json-file, writes log data to JSON-formatted files onthe host filesystem. Over time, these log files expand in size, leading topotential exhaustion of disk resources.

To avoid issues with overusing disk for log data, consider one of the followingoptions:

Next steps

  • Read the Get started training modulesto learn how to build an image and run it as a containerized application.
  • Review the topics in Develop with Docker to learnhow to build new applications using Docker.
Linux post-installation steps for Docker Engine (2024)
Top Articles
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 6344

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.