Add docker container to network under two different names

北城余情 提交于 2019-12-21 21:26:13

问题


I am experimenting with the new docker networking feature. I migrated my old setup using container links to the new bridge network; so far, I have my dedicated bridge network up and running among multiple containers on the same host.
Now I am looking for a means to replicate multiple link aliases for the same container.

Say, I have a container named myBox that joins the docker network. I want to have the same container also reachable as myServer.
Using links, I would simply set up two links with different aliases.
Is there a means to achieve this using docker networking?


回答1:


This is being specified and implemented in docker/libnetwork issue 737

We'd like a container to be able to join a network under different names, not just the container name.

That will help docker compose too: see docker/compose issue 2312.

When using the --x-networking feature in docker-compose 1.5 (docker-engine 1.9), is it possible to get a "simple name" added to /etc/hosts without knowing the container name beforehand and without using the container_name directive?

Update January 2016:

This is now done in 1.6.0 (RC1 is out)

See "Networking in Compose"

Note: The experimental flags --x-networking and --x-network-driver, introduced in Compose 1.5, have been removed.

See PR 19242 and docker network connect:

--alias option can be used to resolve the container by another name in the network being connected to.

$ docker network connect --alias db --alias mysql multi-host-network container2

Also:

You can use --link option to link another container with a prefered alias

$ docker network connect --link container1:c1 multi-host-network container2


来源:https://stackoverflow.com/questions/34037795/add-docker-container-to-network-under-two-different-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!