Explanation:
Update the existing list of packages
ubuntu@ip-172-31-59-138:~$ sudo apt update
Install Docker
************************************************************************************************
Note: execute the following commands to install docker-ce [Docker Community Edition (CE)] or docker-ee [Docker Enterprise Edition (EE)]
#Install packages to allow apt to use a repository over https
sudo apt install apt-transport-https ca-certificates curl software-properties-common
#Add docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# Command to setup the stable repository
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
sudo apt update
#Docker Community Edition (CE)
apt-cache policy docker-ce
sudo apt install docker.ce
#Docker Enterprise Edition (EE)
apt-cache policy docker-ee
sudo apt install docker.ee
*************************************************************************************************
ubuntu@ip-172-31-59-138:~$ sudo apt install docker.io
Verify Docker installation status
ubuntu@ip-172-31-59-138:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; disabled; vendor preset: enabled)
Active: active (running) since Sat 2019-08-24 03:13:13 UTC; 8min ago
Docs: https://docs.docker.com
Main PID: 15011 (dockerd)
Tasks: 8
CGroup: /system.slice/docker.service
└─15011 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.484355658Z" level=warning msg="Your kernel does not support cgroup rt period"
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.484498272Z" level=warning msg="Your kernel does not support cgroup rt runtime"
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.489353437Z" level=info msg="Loading containers: start."
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.663568387Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a preferred IP address"
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.754217392Z" level=info msg="Loading containers: done."
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.758501298Z" level=warning msg="failed to retrieve runc version: unknown output format: runc version spec: 1.0.1-dev\n"
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.806114376Z" level=info msg="Docker daemon" commit=2d0083d graphdriver(s)=overlay2 version=18.09.7
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.806534853Z" level=info msg="Daemon has completed initialization"
Aug 24 03:13:13 ip-172-31-59-138 systemd[1]: Started Docker Application Container Engine.
Aug 24 03:13:13 ip-172-31-59-138 dockerd[15011]: time="2019-08-24T03:13:13.877186101Z" level=info msg="API listen on /var/run/docker.sock"
Add username to the docker group, to avoid using sudo to execute the docker command.
To add user (ubuntu) to any one of the supplementary group (docker), use the options '-a' and '-G'.
ubuntu@ip-172-31-59-138:~$ groups
ubuntu adm dialout cdrom floppy sudo audio dip video plugdev lxd netdev
ubuntu@ip-172-31-59-138:~$ sudo usermod -aG docker ubuntu
ubuntu@ip-172-31-59-138:~$ groups
ubuntu adm dialout cdrom floppy sudo audio dip video plugdev lxd netdev
Restart the SSH to see the changes.
ubuntu@ip-172-31-59-138:~$ groups
ubuntu adm dialout cdrom floppy sudo audio dip video plugdev lxd netdev docker
Run Docker command without sudo
ubuntu@ip-172-31-59-138:~$ docker version
Client:
Version: 18.09.7
API version: 1.39
Go version: go1.10.1
Git commit: 2d0083d
Built: Fri Aug 16 14:20:06 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.09.7
API version: 1.39 (minimum version 1.12)
Go version: go1.10.1
Git commit: 2d0083d
Built: Wed Aug 14 19:41:23 2019
OS/Arch: linux/amd64
Experimental: false
ubuntu@ip-172-31-59-138:~$ docker info