This guide will walk you through deploying the DockerLearn application on an Amazon EC2 instance. DockerLearn is a sample application that demonstrates how to use Docker and Docker Compose to run a multi-container application. The application consists of a frontend, backend, MongoDB, and a web-based MongoDB client (mongo-express).
Before you begin, make sure you have the following:
- An Amazon Web Services (AWS) account.
- Basic knowledge of AWS, EC2, and security groups.
- An EC2 instance launched with a public IP address, and you have downloaded the associated
.pem
private key file.
- Open your terminal.
- Use the
ssh
command to connect to your EC2 instance using the public IP address and the private key file you downloaded:
ssh -i /path/to/your/private-key.pem ec2-user@your-instance-ip
sudo yum update -y
sudo amazon-linux-extras install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
OR
sudo dnf install docker
sudo systemctl start docker
sudo usermod -a -G docker ec2-user
sudo yum install git -y
git clone https://github.com/Audrey-me/dockerLearn.git
cd dockerLearn
docker-compose up -d
You need to configure your security group to allow traffic to the application ports. In this example, we will allow traffic on ports 8080 (frontend), 3000 (backend), and 8081 (mongo-express).
- Open the AWS Management Console.
- Go to the EC2 dashboard.
- Select your EC2 instance.
- Scroll down to the "Security groups" section and click on the linked security group.
- In the "Inbound rules" tab, click "Edit inbound rules."
- Add the following inbound rules:
- Type: Custom TCP Rule, Port Range: 8080, Source: 0.0.0.0/0
- Type: Custom TCP Rule, Port Range: 3000, Source: 0.0.0.0/0
- Type: Custom TCP Rule, Port Range: 8081, Source: 0.0.0.0/0
- Make sure to adjust the source IP ranges based on your security requirements.
You can now access the application through your browser using the public IP address of your EC2 instance:
- Frontend: http://your-public-ip:8080
- Backend: http://your-public-ip:3000
- MongoDB Express (MongoDB client): http://your-public-ip:8081
You can now access the application through your browser using the public IP address of your EC2 instance:
- Frontend: http://your-public-ip:8080
- Backend: http://your-public-ip:3000
- MongoDB Express (MongoDB client): http://your-public-ip:8081