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
Key commands used:
# Building an image with host network access
docker build --network=host -t pankil1812/first-flask-app:0.0.2 .
# Running the containerized application
docker run -d -p 3000:3000 --name first-flask-app pankil1812/first-flask-app:0.0.2
# Checking container logs
docker logs first-flask-app
# Cleaning up unused containers
docker 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
version: '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/
Top comments (0)