Installing Docker and Docker Compose
A step-by-step guide to install Docker, Docker Compose and configuring the docker MTU setting
Before Starting
Supported Installation
This installation procedure is tested on Ubuntu 22.04.x LTS and x86_64 architecture.
Installation
Install Docker
To configure the MTU properly, use Docker from apt
instead of snap
.
If you have already installed Docker through the system installation, remove the snap version of Docker first. Otherwise, skip this step.
Remove snap version of Docker:
Remove old versions of Docker and Docker Compose Plugin:
Remove old versions and install latest version of Docker and Docker Compose Plugin (New Version, Recommended)
Install Docker (Old Version, Not Recommended)
You may test the installation by running:
Fixing Docker permission error (Otional)
If you encounter a permission error like the following when executing docker
commands:
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied
You can either run docker
commands with sudo
, or enable a non-root user to access the docker
command by following these steps:
- Create the
docker
group on the system: - Add the active user to the
docker
group: - Apply the group changes to the current terminal session:
- Check if the
docker
group is in the list of user groups. The group should appear in the command output.
You should now be able to issue Docker commands as a non-root user without using
sudo
.
Install Docker Compose Plugin (Old Version, Not Recommended)
Docker Compose is a tool for defining and running multi-container applications. It appears as a plugin for Docker.
You won't be required to install Docker Compose in order to use Docker, but it is recommended.
Download and install the Compose CLI plugin:
Apply executable permissions to the binary:
You may test the installation by running:
Fixing Docker MTU issue (Otional)
To specify/override the MTU for Docker, add a parameter to the Docker launch script. The file to edit is /lib/systemd/system/docker.service
.
If you're unsure which is the correct file, you can find it using the following command:
Look for the line that starts with Loaded:
and find the path after loaded
. This is the file you're looking for.
To change the MTU setting (for example, to 1400), modify the line in /lib/systemd/system/docker.service
from:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
to:
ExecStart=/usr/bin/dockerd --mtu 1400 -H fd:// --containerd=/run/containerd/containerd.sock
If you're using docker-compose
to launch your instances, you also need to change some configuration to ensure they launch with the specified MTU.
Your Docker Compose file should include the following section:
After making these changes, restart Docker to apply the new MTU setting:
Little tip
Stop all container
If you run into docker start issue, please refer to the following command for solution.
List the mounted volumes of a container
Start Docker Daemon
If you run into the error Cannot connect to the Docker daemon. Is 'docker daemon' running on this host?
when trying to run Docker commands, you can try restarting the Docker daemon using the following command: