Post

Docker Installation on Ubuntu Server 22.04

Docker Installation and Initial Configuration

Although I’ve dabbled in several deployment methods, this page outlines my typical Docker build using Ubuntu Server CLI. The operating system installation is pretty quick overall, and the option to install a minimized version helps reduce the overall bloat by bypassing unnecessary software and utilities.

The particular guide was written for Docker setup on Ubuntu 22.04.

Install Docker using apt repository

1
sudo apt-get update
1
sudo apt-get install ca-certificates curl
1
sudo install -m 0755 -d /etc/apt/keyrings
1
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
1
sudo chmod a+r /etc/apt/keyrings/docker.asc
1
2
3
4
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Update apt again

1
sudo apt-get update

Install the latest version of the docker bundle:

1
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify that the Docker Engine installation is successful by running the hello-world image.

1
sudo docker run hello-world

Source: https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository

Permissions

To create the docker group and add your user:

Create the docker group

1
sudo groupadd docker

Add your user to the docker group

1
sudo usermod -aG docker $USER

Log out and log back in so that your group membership is re-evaluated. You can also run the following command to activate the changes to groups:

1
newgrp docker

Verify that you can run docker commands without sudo.

1
docker run hello-world

Installing Portainer

If you’re not comfortable using Docker commands in the Ubuntu CLI, setting up Portainer for easy viewing and contianer management may be a suitable option for you.

This docker run command will deploy Portainer using the default settings

1
docker run -d -p 8000:8000 -p 9443:9443 --name portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest

If you run multiple Docker hosts on your network, you can install a Portainer agent on subsequent hosts and then join them from the Portainer instance deployed in the previous step

1
2
3
4
5
6
7
docker run -d \
  -p 9001:9001 \
  --name portainer_agent \
  --restart=always \
  -v /var/run/docker.sock:/var/run/docker.sock \
  -v /var/lib/docker/volumes:/var/lib/docker/volumes \
  portainer/agent:2.19.4
This post is licensed under CC BY 4.0 by the author.