Docker Compose - BKJackson/BKJackson_Wiki GitHub Wiki
Docker Compose aggregates individual docker containers and can set dependencies.
- 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
5a. Use environment variables from shell or .env file
5b. Merge multiple Compose files into one, e.g., base config in one file and a deployment-specific config in other files.
Docker compose database setup Source
Note: Add data to .gitignore file
version: '3'
services:
db:
image: mysql:latest
volumes:
- "./data:/var/lib/mysql"
restart: always
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: password
Enter the container with bash:
docker-compose exec --user root db /bin/bash
Enter the MySQL shell:
docker-compose exec --user root db mysql -u root -p
When prompted enter password as the password.
Create a database:
CREATE DATABASE mydatabase;
docker-compose config
environment:
GRANT_SUDO: "yes"
user: root
docker-compose -f docker-compose.yml -f docker-compose.second.yml up
Alternatively, you can create an override file called docker-compose.override.yml and just type
docker-compose up
docker-compose run <name in yml> sh -c '<command 1> && <command 2> && <command 3>'
$ docker-compose up -d
$ ./run_tests
$ docker-compose down
docker stack deploy --compose-file docker-compose.yml --with-registry-auth my-stack-name
Dealing with linked containers dependency in docker-compose
Using Docker Compose for Development Environment Dependencies
PyYAML docs - A YAML parser and emitter for Python. Docs include tutorials and tips.
Local Docker DB - A collection of Docker Compose files I've used to quickly spin local databases of various sorts., Alex MacArthur github
Docker Compose from dev to prod - Good tips
Configure Docker project for different environments using Docker Compose 3 - Sep 6, 2018
Use Compose in production - Official Docker docs
Efficient development with Docker and docker-compose - July 31, 2017
Docker Compose in 12 Minutes - Simple example, includes flask and flask_restful api examples.
“What, Why, How” Docker Compose? - Apr 29, 2019
"Docker compose is a simple yet powerful tool that is used to run multiple containers as a single service."
Getting Started with Docker Compose (Official Docs)
Define named volume with host mount in the docker compose file - example of how to specify .env variables in docker-compose.yml files
Using Docker Compose to Run Your Applications - Oct 16,2018