點燈坊

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

Using Docker on AWS EC2 with Ubuntu

Sam Xiao's Avatar 2021-11-14

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.

ubuntu000

Add Required Packages

$ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Add required packages for Docker.

ubuntu001

Add Official GPG Key

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add official Docker GPG key to source.

ubuntu002

Add Docker

$ sudo apt install docker.io

Add Docker to system.

ubuntu004

$ docker --version

Docker installed successfully.

ubuntu006

Add Docker Compose

$ sudo apt install docker-compose

Add Docker Compose to system.

ubuntu005

$ docker-compose --version

Docker Compose installed successfully.

ubuntu007

Add ubuntu to Docker Group

$ sudo usermod -a -G docker ubuntu

Add user ubuntu to docker group.

ubuntu008

Hello World

$ docker run hello-world
  • Re-login SSH, we can run Docker command without sudu becuase we’ve added ubuntu to docker group
  • Use Docker to run hello-world

ubuntu009

Conclusion

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

Reference

Kamal Hossain, How to run Docker Containers in AWS EC2