Skip to content
/ dcsh Public

Unified 'docker-compose' and 'docker stack' command builder

License

Notifications You must be signed in to change notification settings

egyel/dcsh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dc.sh

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')

Get started

Development environment:

  1. Download and extract the project.
  2. cd into project's main folder: cd dcsh
  3. Execute: ./dc.sh hello-world up

Production environment:

  1. Initiate Docker Swarm mode (if it hasn't been done already): docker swarm init
  2. Set the DC_ENV environment variable to 'prod': export DC_ENV=prod
  3. 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.

Examples

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.

Supported commands

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 >

Environment variables

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

dc.sh flags

  • 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

Project structure

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.

About

Unified 'docker-compose' and 'docker stack' command builder

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published