How To Install Docker On Ubuntu 16.04/18.04

1. Installing Docker

$ sudo apt-get update

$ sudo apt-key adv --keyserver hkp:// --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

$ sudo apt-add-repository 'deb ubuntu-xenial main'

$ sudo apt-get update

Make sure you are about to install from the Docker repo instead of the default Ubuntu 16.04 repo:

$ apt-cache policy docker-engine

You should see output similar to the follow:

  Installed: (none)
  Candidate: 1.11.1-0~xenial
  Version table:
     1.11.1-0~xenial 500
        500 ubuntu-xenial/main amd64 Packages
     1.11.0-0~xenial 500
        500 ubuntu-xenial/main amd64 Packages
$ sudo apt-get install -y docker-engine

Check that Docker is running:

$ sudo systemctl status docker

The output should be similar to the following, showing that the service is active and running:

‚óŹ docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2016-05-01 06:53:52 CDT; 1 weeks 3 days ago
 Main PID: 749 (docker)

Ctrl+C to exit.

add your user to the Docker group with the command:

$ sudo usermod -aG docker $USER

2. Working with Docker images

Once your user has been added, you can run the docker command as your standard user.

To check whether you can access and download images from Docker Hub, type:

$ docker run hello-world

The output, which should include the following, should indicate that Docker in working correctly:

Hello from Docker.
This message shows that your installation appears to be working correctly.


If you get an error like:

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.28/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.

try this:

$ sudo usermod -aG docker $(whoami)

or this:

$ sudo usermod -aG docker yourusername

NOTE: None of these worked for me when using Vagrant local development server. In this case, just prepend all commands with ‘sudo'.

$ sudo docker run hello-world

References & More Info

How does one remove an image in Docker?

How to Use Traefik as a Reverse Proxy for Docker Containers on Ubuntu 16.04

Docker Overview

Docker Tutorials

Docker for beginners

Get Started

1. Set up your Docker environment (on this page)
2. Build an image and run it as one container
3. Scale your app to run multiple containers
4. Distribute your app across a cluster
5. Stack services by adding a backend database
6. Deploy your app to production

More info:

How To Install WordPress and PhpMyAdmin with Docker Compose on Ubuntu 14.04

How to Create a Cluster of Docker Containers with Docker Swarm and DigitalOcean on Ubuntu 16.04
kompose is a tool to help users familiar with docker-compose move to Kubernetes. It takes a Docker Compose file and translates it into Kubernetes resources.

Docker Clustering Tools Compared: Kubernetes vs Docker Swarm

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.