Docker-Compose: Initialize vs Run

I am migrating an existing rails application to docker and docker-compose. There are several scripts that need to be run only when creating containers, for example a script that copies prod db in that and indexes it in Elasticsearch.

From now on, when I launch containers locally for development, I only want to start the rail development server, and not all db initialization scripts. I could make two files for linking dockers (e.g. init and run ) that are the same except for the command: option command: in the webapp container.

Is there a better way?

+5
source share
2 answers

The underlying Docker system does not have a β€œlaunch” concept for custom scripts.

What you can do is one of these approaches:

  • Add a check to your script if it has already done so. Then it doesn’t matter if you repeat it again and again.
  • Integrate db into the docker and send it, as already done with the downloaded data.
  • Make 2 a docking system: the first one will be the docker that you know now with the possible "ONBUILD" command, so the second one will run the script. Then 2nd docker is one of them being original, and will run the script with or without "ONBUILD" above. In docker-compose, you will have a local assembly that will trigger the import when creating a local docker image.

Just an idea

+2
source

You can use extends in your * .yml files.

Extend documentation and examples.

0
source

Source: https://habr.com/ru/post/1216296/


All Articles