How to link docker containers on build?

前端 未结 4 574
悲哀的现实
悲哀的现实 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条回答
  •  野性不改
    2021-02-07 02:39

    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.

提交回复
热议问题