Default Ubuntu on AWS EC2 doesn’t provide Docker and Docker Compose. We have to install them manually.
Version
Ubuntu 20.04
Docker 20.10.7
Docker-compose 1.25.0
Update Package List
$ sudo apt-get update
Update package list to latest version.
Add Required Packages
$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Add required packages for Docker.
Add Official GPG Key
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add official Docker GPG key to source.
Add Docker
$ sudo apt install docker.io
Add Docker to system.
$ docker --version
Docker installed successfully.
Add Docker Compose
$ sudo apt install docker-compose
Add Docker Compose to system.
$ docker-compose --version
Docker Compose installed successfully.
Add ubuntu to Docker Group
$ sudo usermod -a -G docker ubuntu
Add user ubuntu
to docker
group.
Hello World
$ docker run hello-world
- Re-login SSH, we can run Docker command without
sudu
becuase we’ve addedubuntu
todocker
group - Use Docker to run
hello-world
Conclusion
- After installing Docker and Docker Compose on AWS EC2, we can use Docker just like using it on local machine