I linked my app container to postgres on run
:
docker run --link postgres:postgres someproject/develop
and it worked fine.
But I realized that I need to install some stuff to database with django command before run
. So I need linking while build
.
How can I do that?
docker build -h
doesn't have --link
option.
For an easy solution you could use Docker-compose . in you compose file (docker-compose. yml) use the option links Link to containers in another service. Either specify both the service name and a link alias (SERVICE:ALIAS), or just the service name.
I got the answer from the docker contributor Brian Goff:
docker run -d --name mydb postgres docker run --rm --link mydb:db myrailsapp rake db:migrate docker 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 whatever docker run --network whatever --name postgres [etc.] someproject/develop
Then build on that network:
docker build --network whatever [etc.]
Works well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With