Notes

Docker installation - Ubuntu 20.04 LTS

Edit on GitHub

Docker
3 minutes

Install on Ubuntu (easy way)

 1# install
 2# sudo apt install -y docker.io docker-compose
 3
 4curl -sSL https://get.docker.com/ | sh
 5
 6
 7# sudo apt-get update
 8# sudo apt-get install docker-ce docker-ce-cli containerd.io
 9
10# use Docker as a non-root user
11# get rid of having to sudo or be root
12sudo usermod -aG docker $(whoami)
13
14# logout and login again for the group change to work

You don’t need to install the long manual way, docker.io is already provided as a package in the Ubuntu repos and the version is fairly up to date (19.03.8-0ubuntu1 as of this writing, which is the latest version). You can check which version comes with the commandapt info docker.io

docker-apt-info-version

note that in Ubuntu docker is a tray plugin, while docker.io is the Docker containerization software. the name docker wasn’t available so they went with docker.io

Install on Ubuntu (hard way)

Since i had already written this, i’m keeping the content. But the one-liner command above is good enough

 1# uninstall any existing docker
 2sudo apt-get remove docker docker-engine docker.io containerd runc
 3
 4# enable https repos
 5sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
 6
 7# Add Docker’s official GPG key
 8curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
 9
10# add repo
11sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
12
13# install Docker
14sudo apt-get update && sudo apt-get install -y docker-ce docker-ce-cli containerd.io

Since the release for 20.04 LTS is not available as of this writing, i’m adding the bionic repo instead ref. bionic instead of $(lsb_release -cs)

User permissions

If you keep getting permission denied errors like these

docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

This means you need to run the command with sudo. You can get rid of having to sudo by adding yourself to the docker user group

1sudo usermod -aG docker $(whoami)

Make sure you logout and log back in after this in order for the change to work

Upgrade Compose

the docker compose installed with Ubuntu was 1.25.0 while the latest was 1.29.2. i wanted the latest because of .env file changes introduced in +v1.28..

 1# remove any existing installs
 2sudo apt-get remove docker-compose
 3sudo rm /usr/local/bin/docker-compose
 4
 5# curl + grep
 6VERSION=$(curl --silent https://api.github.com/repos/docker/compose/releases/latest | grep -Po '"tag_name": "\K.*\d')
 7DESTINATION=/usr/local/bin/docker-compose
 8# download the current stable release of Docker Compose
 9sudo curl -L "https://github.com/docker/compose/releases/download/${VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o ${DESTINATION}
10
11# Apply executable permissions to the binary
12sudo chmod +x ${DESTINATION}
13
14# create a symbolic link to /usr/bin or any other directory in your path
15sudo ln -s ${DESTINATION} /usr/bin/docker-compose
16
17docker-compose --version # docker-compose version 1.29.2, build 5becea4c