Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure docker-compose override to ignore / hide some containers

Tags:

If I have (simplified), the following docker-compose.yml:

parent:   image: parent   links:     - child  child:   image: child 

Can I construct a docker-compose.override.yml file that will not create or start the child image?


An undesirable (for me) solution, would be to reverse the files, such that the default yml file would create only the parent, and the override would create both.

However, I would like the master configuration file to contain the most common usage scenario.

like image 297
Andrew Stubbs Avatar asked May 09 '16 15:05

Andrew Stubbs


People also ask

What does Docker compose override do?

The docker-compose. override. yml is the configuration file where you can override existing settings from docker-compose. yml or even add completely new services.

Does Docker compose override Dockerfile CMD?

Docker-compose command doesn't override Dockerfile CMD.

How do you scale a docker compose?

Scale via the docker-compose CLI. When you start your application stack by passing your compose file to the CLI docker-compose you can use the flag –scale to specify the scalability of any particular service specified in there.


2 Answers

In defense of the original poster: I totally get why you would want to do this. The docker-compose way always seems to be "put your variation in the override files", but in the interest of keeping things simple within a large development team, I like:

  • The ability to start everything with one command (e.g. "docker-compose up" or "docker-compose up main")
  • All of my docker definitions in one place
    • The only variation in override files to be which containers are disabled

Here's how I did it in my override files:

  # Disable database containers   postgres:     image: alpine:latest     command: "true"     entrypoint: "true"   mysql:     image: alpine:latest     command: "true"     entrypoint: "true" 

The upshot is, all containers are started by "docker-compose up", but those that I've overridden immediately die.

If you want an ever lighter weight container than alpine, try tianon/true.

like image 89
Ryan Avatar answered Sep 29 '22 12:09

Ryan


I really like solution from Ryan. But it can be improved. Create docker-compose.override.yml next to docker-compose.yml with content:

# disable services version "3"  fluentd:     image: hello-world     command: hello     restart: "no"  elasticsearch:     image: hello-world     command: hello     restart: "no" 

I believe hello-world is a smallest image (size: ~1Kb) on the other hand the size of alpine linux is ~6Mb

like image 24
Roman Podlinov Avatar answered Sep 29 '22 11:09

Roman Podlinov