Day 2 of My DevOps Journey: Dockerizing Applications and Multi-Container Setup ๐
After getting comfortable with basic Docker concepts yesterday, I dove deep into creating custom Docker images, deploying to AWS, and setting up multi-container applications. Here's my learning journey from Day 2!
1. Creating Custom Dockerfiles ๐
I created two applications and containerized them:
A Flask application
An Express.js application
Here's the process I followed:
Created the applications locally
Wrote Dockerfiles for each
Built custom images
Pushed them to Docker Hub
# Building an image with host network accessdocker build --network=host -t pankil1812/first-flask-app:0.0.2 .
# Running the containerized applicationdocker run -d -p 3000:3000 --name first-flask-app pankil1812/first-flask-app:0.0.2
# Checking container logsdocker logs first-flask-app
# Cleaning up unused containersdocker container prune
2. AWS EC2 Deployment ๐ฉ๏ธ
Next, I moved to cloud deployment:
Created a free-tier EC2 instance on AWS
Installed Docker on the EC2 instance
Successfully deployed both applications
Accessed them via the EC2 public IP
3. Multi-Container Setup: MongoDB and Mongo Express ๐
The real challenge came with setting up a multi-container application using MongoDB and Mongo Express.
First, pulled the necessary images:
docker pull mongo docker
pull mongo-express
Then, created a network and ran the containers:
# Create a network for container communication
docker create network mongo-network
# Run MongoDB container
docker run --network mongo-network \
-d -p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=password \
--name mongo mongo:latest
# Run Mongo Express container
docker run --network mongo-network \
-e ME_CONFIG_MONGODB_ADMINUSERNAME=admin \
-e ME_CONFIG_MONGODB_ADMINPASSWORD=password \
-e ME_CONFIG_MONGODB_URL="mongodb://admin:password@mongo:27017/" \
-e ME_CONFIG_BASICAUTH=false \
-d --name my-mongoexpress \
-p 8081:8081 mongo-express:latest
But I faced a lot of issues while setting up these because of environment variables. ๐ค But then I tried the new approach of using ME_CONFIG_MONGODB_URL instead of ME_CONFIG_MONGODB_SERVER. ๐
But finally I Successfully accessed Mongo Express UI through the EC2 public IP on port 8081! ๐
4. Introduction to Docker Compose ๐
Finally, I learned about Docker Compose and created two compose files:
Express App Compose File
version: '3'
services:
first-express-app:
image: pankil1812/first-express-app:0.0.1
ports:
- "5000:5000"
MongoDB and Mongo Express Compose File
yamlCopyversion: '3'
services:
mongo:
image: mongo
ports:
- "27017:27017"
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=password
networks:
- mongo-network
my-mongoexpress:
image: mongo-express
restart: always
ports:
- "8081:8081"
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_URL=mongodb://admin:password@mongo:27017/
- ME_CONFIG_BASICAUTH=false
depends_on:
- mongo
networks:
- mongo-network
networks:
mongo-network:
driver: bridge
To implement this:
Stopped all previous containers
Removed the old network
Used
docker-compose -f filename up
to start the services
Key Learnings ๐ฏ
Building and pushing custom Docker images
Cloud deployment with AWS EC2
Network creation and container communication
Environment variable configuration
Docker Compose for multi-container orchestration
What's Next? ๐
For Day 3, I'm planning to explore:
Docker volume management
Container health checks
Docker Compose for development environments
Container orchestration concepts
my github repo for the sources is : https://github.com/pankil-soni/my-devops-journey
the sources where I learned docker from are:
https://www.youtube.com/watch?v=rr9cI4u1_88 https://docs.docker.com/
#Docker #DevOps #AWS #MongoDB #DockerCompose
Subscribe to my newsletter
Read articles from Pankil Soni directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Pankil Soni
Pankil Soni
As a third-year B.Tech. AI & ML student, I am driven by a passion for technology and a desire to contribute to the field of computer science. With a strong foundation in programming languages, algorithms, and data structures, I am eager to learn more about the ever-evolving world of technology. As a student, I am committed to continuous learning and growth. I am eager to explore new technologies, develop new skills, and expand my knowledge in computer science. I am seeking opportunities to apply my skills in a dynamic and challenging environment, and I am excited to connect with professionals in the industry who share my passion for technology.