03. Docker Compose
2 min readJan 16, 2021
There are several approaches to integrate dockers according to the project structure.
Docker-compose approach
- In this approach, each module (web, server, database) resides in different containers.
- We have to write different docker files for each
- There will be different images for each also.
- Only the thing is docker-compose is another top-level file that binds and connects all those images in one project.
- It is the standard approach that helps in the micro-system approach.
- Here initially we have tried it for our project and then switched to another approach.
How docker-compose works?
- Use YAML files to configure application services (docker-compose.yaml)
- Can start all the services with a single command ( docker-compose up )
- Can stop all the service with a single command ( docker-compose down )
- Able to scale up the specific services when required.
- Works in all environments: production, staging, development, testing, as well as CI workflows
Docker-compose file looks like
version: '3'services:
neo4j:
build: ./db
image: "db:1.0"
ports:
- 7474:7474
environment:
- NEO4J_dbms_shell_enabled=trueapi:
build: ./server
image: "server:1.0"
ports:
- 4001:4001
environment:
- NEO4J_URI=bolt://neo4j:7687links:
- neo4j
depends_on:
- neo4jui:
build: ./web
image: "web:1.0"
ports:
- 3000:3000
environment:
- CI=true
links:
- api
depends_on:
- api
- db — it is a database used by the project
- server — It is a server-side module
- web — it is web side module.
- Build, image, port, environment are configurations which helps in building image and linking images with each other.
For more details about the docker-compose approach and implementation go through the following reference links.