After doing your initial sudo yum update -y you can install docker with:

sudo yum install -y docker

Add the ec2-user to the docker group (to avoid the need to sudo when running docker commands): Note! Log out and back in for this change to take effect.

sudo usermod -a -G docker ec2-user

Enable the service to start automatically after a reboot, then actually start the service itself:

sudo systemctl enable docker
sudo service docker start

Final check to verify everything looks ok would be docker -v and docker ps -a should result in output like:

[ec2-user@ip-172-27-0-223 ~]$ docker -v
Docker version 18.09.9-ce, build 039a7df
[ec2-user@ip-172-27-0-223 ~]$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
[ec2-user@ip-172-27-0-223 ~]$

Note that Amazon Linux has an older version of the docker engine, e.g. at the time of this writing the latest available was 19.03, but Amazon’s version is 18.09.

Docker Compose

Install Docker Compose with:

sudo curl -L "https://github.com/docker/compose/releases/download/1.25.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose