1

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.

SecY
  • 307
  • 4
  • 12
  • for /etc/hosts mapping... -> docker ps -q | xargs -n 1 docker inspect --format '{{ .Name }} {{range .NetworkSettings.Networks}} {{.IPAddress}}{{end}}' | sed 's#^/##' – SecY Mar 21 '22 at 00:09

1 Answers1

1

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

Gupta
  • 8,882
  • 4
  • 49
  • 59
  • 1
    Yeah... Thx for your answer. I took a detour to solve this problem. The detour method was written in edited question. – SecY Mar 21 '22 at 00:05