How to Install Docker on Ubuntu 20.04 LTS ⤵️
February 9, 2021•414 words
Single Line Install
curl -sSL https://get.docker.com | sh
Manual Install
sudo apt update
- Update package listsudo apt install apt-transport-https ca-certificates curl software-properties-common
- Install prerequisite softwarecurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- Add the GPG key for the official Docker repositorysudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
- Add the Docker repository to APT sourcessudo apt update
- Again, update the package listapt-cache policy docker-ce
- Ensure we're installing from the Docker repo, rather than Debiansudo apt install docker-ce
- Install Docker- Make docker run automatically on boot:
sudo systemctl enable --now docker
Finally, you can ensure Docker is up and running with: sudo systemctl status docker
. It should now be possible to use the docker
command as normal
Set Permissions
Ideally, you should run containers without root privileges.
sudo groupadd docker
- Create a Docker user group (likely already exists)sudo usermod -aG docker $USER
- Add current user to the docker groupnewgrp docker
- Update group ID for current user
Optional Docker Utilities
If needed, install:
LazyDocker github.com/jesseduffield/lazydocker
Terminal interface for managing docker containers and services
go get github.com/jesseduffield/lazydocker
(requires Go to be installed)
Dozzle github.com/amir20/dozzle
Realtime log viewer for docker containers
docker run --name dozzle -d --volume=/var/run/docker.sock:/var/run/docker.sock -p 8093:8080 amir20/dozzle:latest
dockly github.com/lirantal/dockly
Node app for managing Docker from the command line, similar to LazyDocker
npm install -g dockly
(requires Node.js's npm installed)
Portainer github.com/portainer/portainer
Fully featured web application for managing everything Docker
docker volume create portainer_data
docker run -d -p 8000:8000 -p 9000:9000 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce
cAdvisor github.com/google/cadvisor
Analyzes resource usage and performance characteristics of running containers, has built in Prometheus exporter
docker run --volume=/:/rootfs:ro --volume=/var/run:/var/run:ro --volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro --volume=/dev/disk/:/dev/disk:ro --publish=9000:8080 --detach=true --name=cadvisor --privileged --device=/dev/kmsg gcr.io/cadvisor/cadvisor:$VERSION
Watchtower github.com/containrrr/watchtower
Automatic updates of Docker base images
docker run -d --name watchtower -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower
I typically use LazyDocker, cAdvisor and sometimes Portainer or Dozzle.