Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker-Compose: Initialize vs Run

I'm migrating an existing rails application to docker and docker-compose. There are a few scripts that need to run only at the creation of the containers, for instance a script that copies the prod db into a volume and and indexes it in Elasticsearch.

From then on, when I start the containers locally for development, I only want to run the rails development server and not all the db init scripts. I could make two docker-compose files (say init and run) that are the same except for the command: option on the webapp container.

Is there a better way?

like image 703
rump roast Avatar asked Mar 27 '15 15:03

rump roast


1 Answers

The base Docker system doesn't have an "on run" concept for custom scripts.

What you can do is one of these approaches:

  • Add to your script a check of if it already has done that. Then it doesn't matter if you re-run it again and again.
  • Integrate the db into the docker and ship it as already made with the data loaded.
  • Make a 2 part docker system: The 1st would be the docker you know now with a possible "ONBUILD" command so the 2nd one would run the script. Then the 2nd docker is a one inhering the original one and would run the script with or without the "ONBUILD" above. In docker-compose you would have a local build which would trigger the import while creating the local docker image.

Just an idea

like image 197
Ofir Petrushka Avatar answered Oct 18 '22 00:10

Ofir Petrushka