In docker-compose how to create an alias / link to localhost?

后端 未结 3 1707
Happy的楠姐
Happy的楠姐 2021-02-13 15:00

In my docker-compose file there is a need for several containers to know the hostname of a specific container, including this specific container.

Links will not work, si

3条回答
  •  鱼传尺愫
    2021-02-13 15:06

    extra_hosts did the trick for me.

    extra_hosts:
        - "hostname:127.0.0.1"
    

    From the docker-compose docs:

    extra_hosts Add hostname mappings. Use the same values as the docker client --add-host parameter.

    extra_hosts: - "somehost:162.242.195.82" - "otherhost:50.31.209.229" An entry with the ip address and hostname will be created in /etc/hosts inside containers for this service, e.g:

    162.242.195.82 somehost 50.31.209.229 otherhost

提交回复
热议问题