點燈坊

失くすものさえない今が強くなるチャンスよ

Using Docker on Amazon Linux 2 by AWS EC2

Sam Xiao's Avatar 2021-11-08

Default Linux on AWS EC2 doesn’t provide Docker and Docker Compose. We have to install them manually.

Version

Docker 20.10.7

Update Package List

$ sudo yum update -y

Update package list to latest version.

docker000

Add Docker

$ sudo amazon-linux-extras install docker

Add docker to system.

docker001

Start Docker

$ sudo service docker start

Start Docker as service.

docker003

Docker Group

$ sudo usermod -a -G docker ec2-user

Add ec2-user to docker group.

docker004

Docker Info

$ docker info

Re-login SSH, we can run Docker command without sudu becuase we’ve added ec2-user to docker group.

docker005

Add Docker Compose

$ wget https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m) 
$ sudo mv docker-compose-$(uname -s)-$(uname -m) /usr/local/bin/docker-compose
$ sudo chmod -v +x /usr/local/bin/docker-compose

Add Docker Compose to system.

$ docker-compose version

Docker compose installed successfully.

docker006

Conclusion

  • After installing Docker and Docker Compose on AWS EC2, we can use Docker just like using it on local machine

Reference

AWS, Docker basics for Amazon ECS
AWS, Launch an instance using the Launch Insance Wizard