When to use –hostname in docker?

The --hostname flag only changes the hostname inside your container. This may be needed if your application expects a specific value for the hostname. It does not change DNS outside of docker, nor does it change the networking isolation, so it will not allow others to connect to the container with that name.

You can use the container name or the container’s (short, 12 character) id to connect from container to container with docker’s embedded dns as long as you have both containers on the same network and that network is not the default bridge.

Leave a Comment