Skip to content

01. Setting Up Docker on Ubuntu

Daniel Trolezi edited this page Nov 10, 2024 · 10 revisions

Docker Engine

  1. Setup Docker's apt repository
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
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
sudo apt-get update
  1. Install the Docker packages
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
  1. Verify that the Docker Engine installation is successful by running the hello-world image
sudo docker run hello-world

If you receive the error bellow:

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.

Create the docker group:

sudo groupadd docker

Add your user to the docker group:

sudo usermod -aG docker $USER

Reboot system so that your group membership is re-evaluated.

Ensure the group was added to you user:

groups

Ensure docker is running:

sudo systemctl status docker

If it doesn't, run:

sudo systemctl start docker

Try again, without sudo:

docker run hello-world
  1. List Networks
docker network list
  1. Create Network if there is no network with DRIVER=bridge and SCOPE=local
docker network create bridge
  1. Configure Docker to start on boot with systemd
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

Credential Store (docker-login)

  1. Create new GPG Key
gpg --full-generate-key
  1. Get the GPG Key ID
gpg --list-secret-keys --keyid-format=long

It should return something like:

/Users/hubot/.gnupg/secring.gpg
------------------------------------
sec   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid                          Hubot <hubot@example.com>
ssb   4096R/4BB6D45482678BE3 2016-03-10

In that case, 3AA5C34371567BD2 is the ID.

  1. Set up Password Store
pass init 3AA5C34371567BD2
  1. Store temp password, necessary to proper initialize the service
pass insert docker-credential-helpers/tmp
  1. Check passwords
pass show
  1. Download docker-credential-pass binary from docker-crential-helpers release page

  2. Rename it from docker-credential-pass-v0.8.1.linux-amd64 to docker-credential-pass

$ cp ./docker-credential-pass-v0.8.1.linux-amd64 ./docker-credential-pass
$ rm docker-credential-pass-v0.8.1.linux-amd64
  1. Add binary to $PATH
$ cp ./docker-credential-pass /usr/local/bin/
$ rm docker-credential-pass
  1. Make it executable:
$ sudo chmod +x /usr/local/bin/docker-credential-pass
  1. Verify by running
docker-credential-pass

It should return something like this:

Usage: docker-credential-pass <store|get|erase|list|version>

Docker Desktop

  1. Download latest DEB package and install it
sudo apt-get update
sudo apt-get install ./docker-desktop-<version>-<arch>.deb
  1. Set docker-credential-pass as the credsStore for Docker. Open your ~/.docker/config.json file and change the value of credsStore to pass:
{
   "credsStore":"pass"
}
  1. Login into Docker Hub
docker login
  1. Verify
docker-credential-pass list

And also:

pass show
  1. Remove tmp password created on step 4:
pass remove docker-credential-helpers/tmp
  1. To start Docker Desktop for Linux, search Docker Desktop on the Applications menu and open it.

References