docker/compose

Global service options

maciejpankanin opened this issue · 6 comments

Description

Let's consider a project like this:

  • docker/additional-services.yml - a file containing definitions of services that I don't want to know much about
  • docker-compose.yml - a file containing core services of my project
  • docker-compose.production.yml - a file containing additional configuration for all services that should be applied in production

Example content of the files:

# docker/additional-services.yml

services:
  service1:
    ...
  ...
  serviceN: # as I mentioned before, I don't care how many, and what kind of services this file contains
    ... 
# docker-compose.yml

include:
  - path:
      - ./docker/additional-services.yml

services:
  my-core-service:
    ...
# docker-compose.production.yml

services:
  my-core-service:
    restart: always

The issue is when I run

docker compose -f docker-compose.yml -f docker-compose.production.yml up

I would like to all the services being always restarted, but the only way of achieving this is running:

docker update --restart always $(docker ps -q) 

It is not a clean solution, it would be better if I could

# docker-compose.production.yml

restart: always

and this configuration would apply to the all services. There is a similar solution in the Gitlab CI configuration where

before_script:
    - echo "1 + 1 = "

job1:
  script:
    - echo "2"

job2:
  before_script:
    - echo "2 + 2 = "
  script:
    - echo "4"

would print 1 + 1 = 2 for job1 and 2 + 2 = 4 for job2

What could I do to make it clean?

Just use docker compose restart if you want all service to be restarted.
What's the use-case for this ?