Installing Docker to your AWS EC2 AMI Linux 2 instances

You can use the amazon linux 2 extras repository

sudo amazon-linux-extras install docker

Start the docker service

sudo service docker start

Add the ec2-user (*default user for AWS EC2 amazon Linux instances check usernames via this link - https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connection-prereqs.html)
For Amazon Linux 2 or the Amazon Linux AMI, the user name is ec2-user.
For a CentOS AMI, the user name is centos.
For a Debian AMI, the user name is admin or root.
For a Fedora AMI, the user name is ec2-user or fedora.
For a RHEL AMI, the user name is ec2-user or root.
For a SUSE AMI, the user name is ec2-user or root.
For an Ubuntu AMI, the user name is ubuntu.
Otherwise, if ec2-user and root don't work, check with the AMI provider)

sudo usermod -a -G docker ec2-user

Logout and Log back in.. Try

docker info

Get docker compose (https://docs.docker.com/compose/install/)

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

Apply executable

sudo chmod +x /usr/local/bin/docker-compose

Test installation

docker-compose --version

If you want to stop docker service try sudo service docker stop