Place this in user data when creating the EC2, or run it manually after launch.
#!/bin/bash
sudo yum update -y
sudo amazon-linux-extras install docker
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -a -G docker ec2-user
For verification:
docker -v
docker run hello-world