Skip to content

How to set up docker on Ubuntu

Francesco Nobilia edited this page Feb 23, 2017 · 1 revision

Prerequisites

Docker works only on 64-bit Linux installation and requires version 3.10 or higher of the Linux Kernel. Check before starting

$ uname -r
4.4.0-53-generic

$ uname -a
Linux ip-172-31-19-132 4.4.0-53-generic #74-Ubuntu SMP Fri Dec 2 15:59:10 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Installation

  1. Update apt and ensure APT works with https method and CA certificates are installed

    $ sudo apt-get update
    $ sudo apt-get install apt-transport-https ca-certificates
  2. Add the new GPG key

    $ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
  3. Check your Ubuntu version

    $ lsb_release -r
  4. Create a docker.list file and add an entry for your OS (substitute the placeholder check the Repository list)

    $ sudo vi /etc/apt/sources.list.d/docker.list
    $ echo "<REPO>" | sudo tee /etc/apt/sources.list.d/docker.list
  5. Update APT index

    $ sudo apt-get update
  6. Check if APT is pulling from the Docker repository. Each entry should have the URL https://apt.dockerproject.org/repo/

    $ sudo apt-cache policy docker-engine
  7. Purge the old repo if it exists

    $ sudo apt-get purge lxc-docker
  8. Install recommended prerequisites for the OS

    $ sudo apt-get install linux-image-extra-$(uname -r) install linux-image-extra-virtual
  9. Install docker engine

    $ sudo apt-get install docker-engine

Check the installation

  1. Start Docker

    $ sudo service docker start
  2. Run a sample container

    $ sudo docker run hello-world
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    c04b14da8d14: Pull complete 
    Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9
    Status: Downloaded newer image for hello-world:latest
    
    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/
  3. Stop Docker

    $ sudo service docker stop
  4. Check the service status to be sure that docker has been stopped

    $ sudo service docker status
    ● docker.service - Docker Application Container Engine
       Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
       Active: inactive (dead) since Tue 2016-12-13 14:05:23 UTC; 1min 17s ago
         Docs: https://docs.docker.com
     Main PID: 1862 (code=exited, status=0/SUCCESS)

Configure Docker to start on boot

  1. Update systemd

    $ sudo systemctl enable docker
  2. Reboot and verify that docker is running

Manage Docker as a non-root user

  1. Create docker group

    $ sudo groupadd docker
  2. Add your user to the docker group.

    $ sudo usermod -aG docker $USER
  3. Log out and log back in to re-evaluat your group membership.

  4. Verify that you can docker commands without sudo

  5. Run a sample container

    $ docker run hello-world

Warning: The docker group is equivalent to the root user. For details on how this impacts security in your system, see Docker Daemon Attack Surface for details.

Install Docker Compose

  1. Download the code from the Git repository

    $ sudo curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m)"
  2. Apply executable permissions to the binary

    $ sudo chmod +x /usr/local/bin/docker-compose
  3. Verify the installation

    $ docker-compose --version
    docker-compose version 1.9.0, build 2585387

Install Command-line Completion

  1. Verify that bash-completion is already installed

    $ sudo apt-cache policy bash-completion
  2. Download the completion script

    $ sudo curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
  3. Log out and log back in

  4. Verify that set up keying docker and then pressing TAB

    $ docker
    docker                  docker-containerd-ctr   docker-proxy
    docker-compose          docker-containerd-shim  docker-runc
    docker-containerd       dockerd 

For more details visit