Install Docker - eodeluga/dev-notes GitHub Wiki
Install using the repository
Before you install Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.
Set up the repository
- Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
- Add Docker’s official GPG key:
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
- Use the following command to set up the repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker Engine
- Update the apt package index:
sudo apt-get update
Receiving a GPG error when running
apt-get update?Your default umask may be incorrectly configured, preventing detection of the repository public key file. Try granting read permission for the Docker public key file before updating the package index:
sudo chmod a+r /etc/apt/keyrings/docker.gpg sudo apt-get update
- Install Docker Engine, containerd, and Docker Compose.
To install the latest version, run:
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.
Linux post-installation steps for Docker Engine
These optional post-installation procedures shows you how to configure your Linux host machine to work better with Docker.
Manage Docker as a non-root user
-
Create the docker group. sudo groupadd docker
-
Add your user to the docker group.
sudo usermod -aG docker $USER
- Activate the changes to groups:
newgrp docker
Running Docker under WSL
Because WSL doesn't boot with Systemd, you cannot start the Docker daemon at boot time in the traditional way via a service. So alternatively, you can run the dockerd command via a bashrc script.
This command requires sudo elevation, so to avoid being prompted for a password every time, the command can be added to the sudoers list as follows
- Create a sudo skip script file
sudo touch /etc/sudoers.d/skip_sudo_dockerd
- Open the file
sudo nano /etc/sudoers.d/skip_sudo_dockerd
- Edit the file with the following
%sudo ALL=(ALL) NOPASSWD:/usr/bin/dockerd
- Now edit the .bashrc file
nano ~/.bashrc
- Add the following to the end of the file. This starts the daemon if it is not already running.
# Start Docker daemon at start up
if ! pgrep -x "dockerd" >/dev/null; then
sudo dockerd > /dev/null 2>&1 &
echo "Docker daemon started using: sudo dockerd > /dev/null 2>&1 &"
fi
Close and restart your WSL environment.
Now you should be able to run:
docker run hello-world