Ulrich Schuster
Ulrich Schuster

Reputation: 1916

Add docker container to network under two different names

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?

Upvotes: 4

Views: 9540

Answers (1)

VonC
VonC

Reputation: 1329082

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

Upvotes: 5

Related Questions