Search code examples
dockerdocker-composedocker-swarm

How to change the container name in Docker Swarm?


I deployed docker-compose.yml through Docker Swarm.

The container-name in docker-compose.yml was ignored.

I have to use the designated container name, but "docker container name" cannot be used.

Is there any way?

Actually, I needed this task to map the container ip to /etc/hosts.

docker-compose's links, depends-on is doesn't work.

I solved this problem with the "docker inspect" command. and volume mount between docker inspect's result and container's /etc/hosts.


Solution

  • It is expected behavior.

    As per Official Docker Doc

    Note when using docker stack deploy
    
    The [container_name][1] option is ignored when [deploying a stack in swarm mode][1]
    

    Note: Checkout Other SO Answer