Page tree
Skip to end of metadata
Go to start of metadata

This document describes how to install docker-ce on Ubuntu 16,04,3 LTS, which is the most current supported version of Ubuntu. This follows the official Docker installation guide for Ubuntu.

Step-by-step guide

  1. Install required packages. Some of these may already be at the latest version; if so, they will be automatically be skipped. Note that for Ubuntu 16.04 and higher, the Linux kernel includes support for OverlayFS, and Docker CE will use the overlay2 storage driver by default.

    sudo apt-get update
    
    sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common
  2. Add the official GPG key for Docker.

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  3. Verify the fingerprint is correct (9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88)

    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
  4. Set up the stable Docker repository and update the apt package index.

    sudo add-apt-repository \
       "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
       $(lsb_release -cs) \
       stable"
    
    sudo apt-get update
  5. Install the latest version of Docker CE (note this will install other packages as required)

    sudo apt-get install docker-ce

    Verify that Docker CE is installed correctly by running a small container.  This will download a test image and run a container.  It will print an informational message if it runs successfully.

    sudo docker run hello-world
    
    ##message from a successful installation:
    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 ID:
     https://cloud.docker.com/
    
    For more examples and ideas, visit:
     https://docs.docker.com/engine/userguide/
  6. Some default options need to be changed.  There are two ways to do this.  One is to adjust /etc/default/docker file and the /lib/systemd/system/docker.service file . The other way involves creating a /etc/docker/daemon.json file.  This requires a slight modification of the /lib/systemd/system/docker.service file if the hosts option is being modified.  Both ways are listed here. There are a few reasons you may want to adjust this file, including using a different directory for the default docker files.Another reason is ensure the docker daemon uses both the tcp socket and the unix socket.

    Note these directions are for Ubuntu 16.04.3 LTS and above.  Older versions of Ubuntu do not use systemd.  If using an older system, changing the /etc/default/docker file should suffice.  However, some options may be deprecated by Docker in future versions.

    1. Before beginning, stop docker and make adjustments if you are changing the default directory for docker files

      ##Stop Docker
      sudo service docker stop
      
      ##Create a new directory if you are changing the default directory for docker files 
      sudo mkdir -p /data/docker
    2. Method 1:

      1. Example DOCKER_OPTS section of /etc/default/docker file.  More information on some of the options that can be used is available here.

        ## -g is the root of the docker runtime (default is /var/lib/docker)
        ## -H is the daemon socket(s) to connect to
        ## In this example we modified the docker directory location and set the tcp port.  By default docker connects to the unix daemon socket. 
        ## It has to be listed in the file so it's not overwritten by just the tcp daemon socket
        
        DOCKER_OPTS="\
        -g /data/docker  \
        -H unix:///var/run/docker.sock \
        -H tcp://0.0.0.0:2375
      2. Changes in the /lib/systemd/system/docker.service file Service section so it will use the /etc/default/docker file.

        ##Add this to the [Service] section
        # This line is sufficient if DOCKER_OPTS variable does not have to be expanded:
        #EnvironmentFile=-/etc/default/docker
        # Use this line to expand DOCKER_OPTS variable:
        ExecStartPre=/bin/sh -c ". /etc/default/docker && /bin/systemctl set-environment DOCKER_OPTS=\"$DOCKER_OPTS\""
        
        ##Change the ExecStart line
        #ExecStart=/usr/bin/dockerd -H fd://
        ExecStart=/usr/bin/dockerd  $DOCKER_OPTS
    3. Method 2 (this is the recommended method according to the latest Docker documentation)
      1. Create /etc/docker/daemon.json file (note some of the names of the parameters have changed).  More information is available here and here

        {
          "hosts" : ["unix:///var/run/docker.sock", "tcp://0.0.0.0:2375"],
          "graph" : "/data/docker"
        }
      2. Make changes to the /lib/systemd/system/docker.service file to remove the -H fd:// startup option in the ExecStart only if the "hosts" option is used in the daemon.json file

        ##Original entry:
        #ExecStart=/usr/bin/dockerd -H fd://
        
        ##Modified Entry
        ExecStart=/usr/bin/dockerd
    4. Restart docker

      ##Reload the systemctl daemon if changes were made to /lib/systemd/system/docker.service file
      sudo systemctl daemon-reload 
      
      ##restart docker
      sudo service docker start
      
    5. If the default docker directory file location was changed, verify new files are being written to that directory, and then delete the old docker directory if desired.

      ##In the example, we changed the default docker directory to /data/docker.  These are the directories that should exist once the docker daemon is restarted:
      
      aufs  containers  image  network  plugins  swarm  tmp  trust  volumes
      
      ##do not do this on a system that is not being initially setup or you could lose information and potentially break the system
      sudo rm -r /var/lib/docker

    If you already have containers defined and you make a change to the default docker file locations, they will no longer be working.  Restart them with docker-compse up -d and the volumes, networks, and containers will be redefined.  If you have already loaded data, you will need to re-import.

  7. Install docker-compose.  Docker-compose is not an application like docker and is not obtained/updated using the normal package manager (and is not updated with the apt package).  It is a file downloaded from github.  Specify the version when downloading.  The list of docker-compose releases is here.  To install a new version, use the same command and specify the new version to be installed.

    If you get a "permission denied" error message while running the curl command, it means the /usr/local/bin directory is not writable.  Become the sudo user (sudo -i or sudo -s) and rerun the curl command (and the chmod command)

    curl -L https://github.com/docker/compose/releases/download/1.15.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
    
    sudo chmod +x /usr/local/bin/docker-compose
  8. Verify the versions of docker-compose and docker-ce that have been installed using either --version or -v

    docker -v (or docker --version)
    Docker version 17.06.0-ce, build 02c1d87
    
    docker-compose -v (or docker-compose --version)
    docker-compose version 1.15.0, build e12f3b9
  9. Note - you may want to add a user/users specifically to the docker group.  After installing the ssdt utilities, I ran into an error message when I ssh'd into the server (it didn't cause any issues).  Adding my username to the docker group resolved the message.

    sudo usermod -a -G docker username
  10. See this link for some generic Linux commands.