How to link docker containers on build?

前端 未结 4 621
悲哀的现实
悲哀的现实 2021-02-07 01:44

I linked my app container to postgres on run:

docker run --link postgres:postgres someproject/develop

and it worked fine.

4条回答
  •  萌比男神i
    2021-02-07 02:27

    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.

提交回复
热议问题