Day 23 of 90 Days of DevOps Challenge: Docker Networking & Docker Compose


As containerized microservices become the industry standard, understanding how containers communicate and how to manage multi-container setups becomes essential for any DevOps engineer. Today, I focused on two crucial components of Docker:
Docker Networks – Enabling secure and structured communication between containers.
Docker Compose – Simplifying the orchestration of multi-container applications.
Docker Networks
Docker networking allows containers to communicate with each other, with the host machine, and with external systems. Understanding the types of networks available in Docker is essential for structuring secure and efficient communication.
Default Docker Networks:
bridge:
Default network for standalone containers.
Assigns a private IP address to the container.
Containers can communicate over the same bridge network.
host:
Container shares the host’s networking stack.
No separate network namespace, which can offer slight performance benefits.
none:
No networking is applied.
Used when network isolation is required.
Additional Docker Network Drivers:
overlay – Used for Docker Swarm mode; allows communication between containers on different hosts.
macvlan – Assigns a physical IP address to a container; often used when direct network access is required.
Common Docker Network Commands:
docker network ls # List all networks
docker network create <name> # Create a custom network
docker network inspect <name> # View detailed info about a network
docker network rm <name> # Remove a network
docker run -d -p 8080:8080 --network <name> <image> # Connect container to a custom network
Docker Compose – Managing Multi-Container Applications with Ease
As applications evolve from monolithic to microservices architectures, managing multiple containers manually becomes impractical. Docker Compose solves this problem by letting you define, configure, and run multi-container applications using a single YAML configuration file.
What is docker-compose.yml?
A YAML file that defines:
version – Docker Compose version used.
services – List of containers to run and their configurations.
networks – Custom network definitions (optional).
volumes – Define persistent storage locations for container data.
Note: Docker Compose is ideal for local development and testing environments. In production, orchestration tools like Kubernetes are typically preferred.
Installing Docker Compose (Linux)
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose # permissions
docker-compose --version # check version
Practical Demo: Spring Boot App + MySQL with Docker Compose
To reinforce today's concepts, I deployed a real-world Java Spring Boot application backed by a MySQL database, using Docker Compose.
docker-compose.yml Sample
version: "3"
services:
application:
image: spring-boot-mysql-app
ports:
- "8080:8080"
networks:
- springboot-db-net
depends_on:
- mysqldb
volumes:
- /data/springboot-app
mysqldb:
image: mysql:5.7
networks:
- springboot-db-net
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=sbms
volumes:
- /data/mysql
networks:
springboot-db-net:
Application Deployment Steps:
# Clone the repository
git clone https://github.com/ashokitschool/spring-boot-mysql-docker-compose.git
cd spring-boot-mysql-docker-compose
# Build the Spring Boot project using Maven
mvn clean package
# Build Docker image
docker build -t spring-boot-mysql-app .
# Start containers
docker-compose up -d
# Check running containers
docker-compose ps
# Manage container lifecycle
docker-compose stop # Stop containers
docker-compose start # Restart containers
docker-compose down # Remove containers
Final Thoughts
Understanding how containers communicate and how to manage them at scale is crucial in the DevOps workflow. Docker Networks help structure secure, scalable communication between services, while Docker Compose enables easy orchestration of those services during development and testing.
Tomorrow, I’ll dive deeper into Docker Volumes, exploring how to persist data across container lifecycles and manage configurations using environment variables.
Thanks for following along!
Let’s keep learning and building, one container at a time..
Subscribe to my newsletter
Read articles from Vaishnavi D directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
