Skip to content

Install Docker on Ubuntu or Debian

Installing Docker on Ubuntu or Debian only takes a few commands. This should all take only a few minutes. Let’s dive in.

First, you need to remove any Docker dependencies. (If you’ve never installed Docker before, don’t worry. You can skip this step.)

Terminal window
$ sudo apt-get remove docker docker-engine docker.io containerd runc

Now we need to set up the Docker repository, add the official GPG key, and verify it.

Terminal window
$ sudo apt-get update
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common

Next, we add the GPGKey.

Terminal window
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -

Now, we need to verify the fingerprint and check it matches this:

  • 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
Terminal window
$ sudo apt-key fingerprint 0EBFCD88
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 that’s all good, we add the Docker repository.

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

Okay, now that we’ve got the repository set up and verified, it’s time to install Docker.

Terminal window
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io

At this point, it’s good to start a container to check that Docker installed correctly.

Terminal window
$ sudo docker run hello-world

You’ll notice that if you want to start Docker as a non-root user, you’ll probably run into this error message.

Terminal window
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.40/containers/json: dial unix /var/run/docker.sock: connect: permission denied

Don’t worry. There’s an easy fix for that. First, create the docker group.

Terminal window
$ sudo groupadd docker

Then add the non-root user to the group.

Terminal window
$ sudo usermod -aG docker $USER

With all that done, you’ve got Docker set up and ready to use.