How to link docker containers on build?

前端 未结 4 578
悲哀的现实
悲哀的现实 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:29

    I had a similar issue. I wanted to speed up image builds with the help of apt-cacher. It runs in its own container and somehow other images, which I built, had to communicate with it.

    The solution was to publish apt-cacher port on all interfaces. This includes e.g. docker0, which is available to intermediate containers spawned during image build.

    Example Dockerfile:

    FROM debian:8
    
    RUN ping -c 2 172.17.0.1
    

    And this is how it builds:

    $ docker build -  47af6ca8a14a
    Step 2 : RUN ping -c 2 172.17.0.1
     ---> Running in 4f56ce7c7b63
    PING 172.17.0.1 (172.17.0.1): 56 data bytes
    64 bytes from 172.17.0.1: icmp_seq=0 ttl=64 time=0.117 ms
    64 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=0.130 ms
    --- 172.17.0.1 ping statistics ---
    2 packets transmitted, 2 packets received, 0% packet loss
    round-trip min/avg/max/stddev = 0.117/0.123/0.130/0.000 ms
     ---> 5c73a36a0a6a
    Removing intermediate container 4f56ce7c7b63
    

提交回复
热议问题