How to run docker containers in AWS EC2
December 21, 2020
Click Counter app app to deploy at AWS EC2 ubuntu instanceGet the source code here
If docker is installed you can build and run images locally.
docker-compose up --build
Set the
REACT_APP_API_URLvariable in .env, based on your need.
Configure Security Group add All traffic rule and allow from anywhere ( for testing only )Load the downloaded *.pem file*.ppk file )connectssh ( the part should start with ubuntu and end with .com )Session, paste the copied name in Host Name (or IP address) leave port as 22Connection > SSH > Auth and browse the saved private key ( *.ppk ) in Private key file for authenticationOpenYes ( if anything prompt up )Run the following commands to install docker and docker compose
sudo apt-get update
sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
apt-cache madison docker-ce
sudo apt install docker.io
sudo apt install docker-compose
Run this repo in AWS EC2 by following commands
git clone https://github.com/kamal-hossain/MERN-docker-ec2-deploy-practice
cd MERN-docker-ec2-deploy-practice
sudo docker-compose up --build
You can also run it background by adding -d flag
sudo docker-compose up --build -d
Confirm it by
sudo docker ps
Stop the containers
sudo docker-compose down
To access the app from browser do the followings:
Public IPv4 address from DetailsYou can't access the IP if
All trafficis not enabled inSecurity groupfrom anywhere. (Or simillar settings)
Resource(s): 1