How to link docker containers on build? How to link docker containers on build? django django

How to link docker containers on build?


I got the answer from the docker contributor Brian Goff:

docker run -d --name mydb postgresdocker run --rm --link mydb:db myrailsapp rake db:migratedocker run -d --name myapp --link mydb:db myrailsapp

This is going to fire up postgres.Fire up a container which does the db migration and immediately exits and removes itself.Fires up the rails app.

Think of the build process like compiling an application. You don't seed data into a database as part of the compilation phase.


True, but docker build does accept the --network option.

You can put your prerequisite containers on a named / custom network, e.g.:

docker network create whateverdocker run --network whatever --name postgres [etc.] someproject/develop

Then build on that network:

docker build --network whatever [etc.]

Works well.


You can not do this. You could either build a child image of postgres, or update the database every time you start the container.