Install Docker

In this session, we will install and setup docker in a simple and easy way on Amazon Linux 2.

  • Launch a EC2 instance (Amazon Linux AMI)

  • Ensure to allow port 80 on your Security group

  • Login to the server via SSH to the server using the public DNS and the public key

$ ssh -i <<keypair>.pem ec2-user@<FQDN of the server>
  • Refresh repository and Install the latest version of Docker using yum.
$ sudo yum update -y
$ sudo yum install -y docker
  • Start the docker service.
$ sudo service docker start
  • In order to user docker command without root privileges (sudo), we need to add ec2-user to the docker group:
$ sudo usermod -aG docker ec2-user
  • Exit your session and access the server again via SSH in order to update the user permissions
$ exit
ssh -i <<keypair>.pem ec2-user@<FQDN of the server>
  • To verify that docker is correctly installed, use the below command.
$ docker info 
  • If everything is installed properly you will see information such as docker version, Runtime etc
Containers: 11
 Running: 0
 Paused: 0
 Stopped: 11
Images: 2
Server Version: 18.06.1-ce
Storage Driver: overlay2
 Backing Filesystem: xfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.14.114-105.126.amzn2.x86_64
Operating System: Amazon Linux 2
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 1.945GiB
Name: ip-172-31-31-158.ec2.internal
ID: 2QKP:NDTO:37EM:ERY6:2HUZ:WNPV:N45U:4ZBW:6VK7:NRDI:CLVN:7WLU
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false