Skip to content

Installing Docker

Sundara Tejaswi Digumarti edited this page Nov 12, 2019 · 2 revisions

This step is for those that want to install Docker locally (Scenario 1) and for Administrators of the remote machine (Scenario 2). If you just plan on using docker that is already installed in a remote machine, move to the next section.

The following has been tested on Ubuntu 18.04 using Docker Community Engine version 19.03.4 and has been adapted from here. Installation guide for Windows and OSX is available here. We will be installing Docker from the official Docker repository and not from the one in the Ubuntu repository.

Installation

Open a terminal and upate your existing list of packages.

sudo apt-get update

Install pre-requisites for Docker.

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Add the GPG key for the official Docker repository.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the Docker repository to APT sources.

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"

Update your packages again so that the Docker repository is found.

sudo apt-get update

Check that you are about to isntall from the Docker repository and not from the Ubuntu repository.

apt-cache policy docker-ce

The output of the above command should be something like the following and you should note that Installed is (none) and that the download is from https://download.docker.com.

docker-ce:
  Installed: (none)
  Candidate: 5:19.03.4~3-0~ubuntu-bionic
  Version table:
  5:19.03.4~3-0~ubuntu-bionic 500
        500 https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
        100 /var/lib/dpkg/status

Install Docker.

sudo apt-get install docker-ce

Check that Docker is installed and set to start on boot.

sudo systemctl status docker

The output should be similar to the following.

● docker.service - Docker Application Container Engine
  Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
  Active: active (running) since Thu 2019-10-31 07:43:41 AEDT; 1min 05s ago
    Docs: https://docs.docker.com
Main PID: 1887 (dockerd)
   Tasks: 33
  CGroup: /system.slice/docker.service
          └─1887 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
...

Using docker without root access

  • This is an important step for the remote machine administrators to allow non-administrator users to use docker.
  • This step requires that there is a user with administrator privileges who can add a user to the docker usergroup.

Docker can only be run by the root user or any user belonging to the docker usergroup, which is created automatically upon installation. So, you either need to add sudo before the docker commands or you need to manually add the user to the docker group.

You can check this by typing the following. You will see that permission to connect to the docker daemon is denied.

docker images

Note: A few basic docker commands , e.g. to check version of docker, will work without root access.

You can also check all the usergroups your user is a part of by typing the following. Replace <username> with your user name.

id -nG <username>

By default docker should not be listed in the output.

Adding a user to the docker group

This step can only be performed by a user with administrator privileges. In the following command replace <username> with the name of the user that needs to be added to the docker group.

sudo usermod -aG docker <username>

The user has to log out and log back in for the effect to be applied. Otherwise the following command can be typed, which simulates logging in, in order to apply the changes. The user's password needs to be typed.

su - <username>

Confirm that the user has been added to the docker usergroup by checking the output of the following which should now show docker in the output.

id -nG <username>

Re-run the docker command and check that you no longer get the permission denied message.

docker images

Removing a user from the docker group

If a user has to be removed from the docker group, then the following command can be used.

deluser <username> docker