Adding network alias to container already in network

Hi I’m asking if it’s possible to add aliases to a container that is already in a network?

For example when I run the following (to add rockmelon-storage as a new alias)

docker network connect --alias 'rockmelon-storage' rockmelon-storage-default-f537679b_WebServer rockmelon-storage-default-f537679b-microservice-1

I get the following error

Error response from daemon: endpoint with name rockmelon-storage-default-f537679b-microservice-1 already exists in network rockmelon-storage-default-f537679b_WebServer

Looking online it seems the only solution is to disconnect the container from the network then re-add it with the existing aliases and the new one.

Is there a better way to approach this? Is this the recommended solution?

I don’t think you can add a new alias without disconnecting the container from the network. You could add a new network to each related container with the alias. You could also use Docker Compose so changing network aliases would be fast enough so nobody would notice it.

update: My original comment was confusing since I started a sentence with one thought and finished wth another. I fixed it now.

1 Like