How to setup Docker on Ubuntu

- 3 min read

The Docker documentation for installing Docker CE under Ubuntu is really fantastic. This guide aims to provide a very opinionated step-by-step setup to give most developers a straightforward installation for local dev work.

All commands in this guide are taken from the Docker CE Ubuntu installation guide and was tested with the latest LTS version of Ubuntu, 18.04.

Install Docker repository

We’ll install Docker through the repository, so that it is easy to update and we can be sure we receive the latest stable version.

To support the Docker repository, we need to ensure we can use the repo over HTTPS.

First update our sources:

sudo apt update

Next, install packages needed to work with the Docker source over HTTPS:

sudo apt install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common

Add Docker’s GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

You should now be able to run apt-key finger 0EBFCD88 to confirm the fingerprint:

pub   4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub   4096R/F273FCD8 2017-02-22

If your fingerprint doesn’t match what I have above, please check the Docker CE documentation for the fingerprint step. If the fingerprint from Docker has changed please let me know on Twitter so that I can correct this guide. If the fingerprint has not changed, you have a security issue in your machine/network.

Finally, add the repository:

sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

Install Docker CE

Now that our sources are pulling from Docker CE we need to update again:

sudo apt update

Then install Docker:

sudo apt-get install docker.io

Note, an old version of this guide instructed installing docker-ce. However it looks like Docker has updated the package name to docker.io, if docker.io doesn’t work, try sudo apt-get install docker-ce.

Execute Docker commands without sudo

Docker’s Linux Post Install documentation includes some great steps you may want to follow. The one that is the most meaningful to me is to execute Docker commands without sudo by adding yourself to the docker group.

First, ensure the docker group exists, if it does you’ll receive an error that groupadd: group 'docker' already exists which you can ignore.

sudo groupadd docker

Next, add your user to the Docker group.

sudo usermod -aG docker $USER

Now, you can either completely log out and log back in or… you can just run this command to add the group to your current session:

newgrp docker

Test your installation

Now perform a Docker run commant to ensure Docker is working (you should see the word success after running your command):

docker run --rm -it --init alpine echo "success"

If you ran into any issues please let me know on Twitter.

Next steps

If you’re already an advanced user of Docker or are planning to install Kubernetes, you can follow my guide for installing Minikube on a KVM virtual machine under Ubuntu.