Installing Docker on Ubuntu

Installing Docker on Ubuntu

This post is essentially my notes on getting started quickily with Docker. I set this up in my lab machines running Ubuntu 16.04.1 LTS, the steps are based on the excellent instructions written on the Docker getting started guide

Add the Docker project repository to APT sources

sudo apt-get install apt-transport-https ca-certificates
sudo apt-key adv  \
              --keyserver hkp://ha.pool.sks-keyservers.net:80  \
              --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list

If you are using a different version of Ubuntu check this page for the right repository address to use. After the repository has been added update packages list to retrieve packages in the newly added repository

sudo apt-get update

Install Docker

Verify that APT is pulling from the right repository, the output of the following command should have entries pointing to the URL https://apt.dockerproject.org/repo/

apt-cache policy docker-engine

The output should look like this

docker-engine:
  Installed: 1.12.5-0~ubuntu-xenial
  Candidate: 1.12.5-0~ubuntu-xenial
  Version table:
 *** 1.12.5-0~ubuntu-xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
        100 /var/lib/dpkg/status
     1.12.4-0~ubuntu-xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.3-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.2-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.1-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.12.0-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.2-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.1-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
     1.11.0-0~xenial 500
        500 https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

Install recommended packages

sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual

Install the Docker engine

sudo apt-get install docker-engine

Set up a docker group

So that unpriviledged users can run Docker images, create a docker group and add the users to it

sudo groupadd docker
sudo usermod -aG docker $USER

The above command will add the currnelty logged in user to the docker group. You will need to logout and back in again for the group memberships to be updated

Start Docker

Start the Docker engine by running this command

sudo service docker start

You can test if the installation went fine by running the hello-world image

docker run hello-world

You should get an output similar to this


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

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker Hub account:
 https://hub.docker.com

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

Your machine is now properly set up with Docker and you can start running Docker images.

 
comments powered by Disqus