Docker Compose
Docker compose is a yml file or a tool for defining and running multi-container docker applications, its a file that contains how to build and deploy containers
The below link is a guides on how to install docker compose in a docker :
A docker-compose.yml file is organized into four sections:
version : Specifies the Compose file syntax version.
services : In Docker a service is the name for a “Container in production”. This section defines the containers that will be started as a part of the Docker Compose instance.
networks: This section is used to configure networking for your application. You can change the settings of the default network, connect to an external network, or define appspecific networks
Volume : Mounts a linked path on the host machine that can be used by the container.
Most of this guide will focus on setting up containers using the services section. Here are some of the common directives used to set up and configure containers:
image, restart, depends_on, environment.
Below are different docker-compose yml file that creates an application and the database respectively such that the application talks to the database :
Example 1: (Volumes & Networks also will be created by docker compose)
# docker-compose.yml
version: '3.1'
services:
app:
image: mylandmarktech/myapp:6
restart: always # This will be ignored if we deploy in docker swarm
environment:
- MONGO_DB_HOSTNAME=mongod
- MONGO_DB_USERNAME=devdb
- MONGO_DB_PASSWORD=devdb123
ports:
- 8080:8080
networks:
- wellsfargo
mongod:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=devdb
- MONGO_INITDB_ROOT_PASSWORD=devdb123
volumes:
- mydatas:/data/db
restart: always
networks:
- wellsfargo
volumes:
mydatas:
Recommended by LinkedIn
driver: local
networks:
wellsfargo:
driver: bridge
Example 2: (Volumes & Networks will not be created by docker compose.As we set volumes and networks as external)
==========
version: '3.1'
services:
app:
#replicas: 4
image: mylandmarktech/myapp:6
restart: always # This will be ignored if we deploy in docker swarm
environment:
- MONGO_DB_HOSTNAME=mongod
- MONGO_DB_USERNAME=devdb
- MONGO_DB_PASSWORD=devdb123
ports:
- 8080:8080
networks:
- wellsfargo
mongod:
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=devdb
- MONGO_INITDB_ROOT_PASSWORD=devdb123
volumes:
- mydatas:/data/db
restart: always
networks:
- wellsfargo
volumes:
mydatas:
external: true
networks:
wellsfargo:
external: true