Unified 'docker-compose' and 'docker stack' commands.
Thanks to Docker's team, we can use the same yml files in 'docker-compose' and in 'docker stack', but unfortunately, the commands are slightly different. This project has been born from the frustration of the confusing the commands and their order.
With dc.sh, ./dc.sh service-name up
means executing:
- 'docker-compose -f docker-compose.yml -p service-name up' in development environment,
- 'docker-compose -f docker-compose.yml -p service-name config | docker stack deploy -compose-file - service-name' in production. (Or with
./dc.sh -F service-name up
executing 'docker stack deploy -c docker-compose.yml service-name')
Development environment:
- Download and extract the project.
- cd into project's main folder:
cd dcsh
- Execute:
./dc.sh hello-world up
Production environment:
- Initiate Docker Swarm mode (if it hasn't been done already):
docker swarm init
- Set the DC_ENV environment variable to 'prod':
export DC_ENV=prod
- Follow the instruction described above in the "Development environment". The dc.sh script will translate the 'docker-compose up' command to 'docker stack deploy' command.
For more complex/interesting examples, try out ./dc.sh quickstart up -d
instead of 'hello-world', and hit http://localhost:8080 in the browser.
There are two examples:
- hello-world: executes the simple hello-world image that comes with Docker installation in the verification step;
- quickstart: the Docker's Quickstart Guide implementation.
Currently supported command "translations":
dc.sh | docker-compose | docker stack |
---|---|---|
up | up | deploy |
start | start | deploy |
config | config | NONE: fall back to docker-compose |
build | build | NONE: fall back to docker-compose |
< command > | < command > | < command > |
Only the DC_ENV is important to set in the production, others are for more granular control.
- DC_ENV Enviroment [ dev | prod ]; default: dev
- DC_MODE Used docker command [ compose | stack ]; default: if DC_ENV==prod then 'stack' else 'compose'
- DC_FS Way to pass yml file to 'docker stack deploy' [ conf | file ]; default: conf
- E Only show (echo) the command without executing it
- [D|P] Override DC_ENV: D = dev; P = prod
- [C|S] Override DC_MODE: C = docker-compose; S = docker stack
- F Pass yml files directly to 'docker stack deploy' instead of using docker-compose config. Same as DC_FS
The dc.sh script uses the services defined in the services/ folder and the custom docker images defined in the docker/ folder.
- .env: the global/default environment settings
- dc.sh: unified script for running a service in dev/prod environment. See the help (
./dc.sh
) for more info. - docker-compose.yml: the global yml file. This file contains the settings that all services needs. (e.g.: set network)
- docker: custom docker images per folders
- service: each sub-folder is a service
- docker-compose.base.yml: the base composes setting. The dc.sh combines it with 'dev' or 'prod' adjustments, depending of DC_ENV setting.
- docker-compose.dev.yml: development adjustment. Set here your specific environment. (e.g.: set more detailed log level, etc.)
- docker-compose.prod.yml: the same as the 'dev' above for production. (e.g.: do not expose the unnecessary ports, uses external secrets, set healthcheck, etc.)
Thanks to Clientele Zone for sponsoring this project.