Cannot access docker container through hostname, works with IP

I am very new to docker, this is the first time I’m using it and it’s for work.

I am running windows 11 and have created a new business central container.

Unfortunately, I am unable to access it through the hostname/bc URL. Instead, I must type in the IP adress/BC and only then it works.

Does anyone know how to fix this? I checked the hosts file in C:\Windows\System32\drivers\etc and I manually added the ip adress/hostname combination but it still doesn’t work.

An additional question is that the IP for my container keeps changing every time I start it up. Is there a way to keep it static? I thought this was a local container, why does it even have an IP address?

Please excuse if any of this is a dumb question, as I said this is the first time I’m using Docker. Ask any clarifying questions you may have.

Recommended links to learn the basics and concepts:

The last link is (currently) about Docker Desktop which is Docker CE in a virtual machine whith a GUI.


If you share what you do actually, help can come faster, but using container names as hostnames works only with custom docker networks which Docker Compose creates by default. If you use the docker run command, you have to create a network with docker network create.

How else would you use a hostname to access a specific container and use the same port inside any container? ONe of the best features of containers is the network isolation.

You also seem to use Docker Desktop for Windows (am I right), but you opened the topic in the Docker Engine category which runs inside the virtual machine of Docker Desktop so you will need port mappings as well which is mapping a port from the host to a containers ip address in the VM. You can find more about docker networks in my tutorial website I linked above, or you can find it also on dev.to:

Hello rimelek, thank you for your comment.

You are correct that I am using Docker Desktop for Windows. This is in my hosts file:

Added by Docker Desktop

192.168.0.31 host.docker.internal
192.168.0.31 gateway.docker.internal

To allow the same kube context to work on the host and the container:

127.0.0.1 kubernetes.docker.internal

End of section

1XX.XX.133.121 stefan

When I go to

http://1XX.XX.133.121/BC my Business Central database opens up. But if I try to access it through http://stefan/BC it just gives me “Unable to connect” error.

When I launch my app from VSCode it automatically opens up into stefan/BC. And I can’t even hardcode the IP because it changes every time I restart the container.

I hope you understand what I mean now.

Container hostnames wouldn’t work from the host machine (outside containers) with Docker CE either and docker Desktop runs everything in a virtual machine, so even the container IPs are private in the VM, you can’t access them from the host. I worte about that too in linked blogpost. You need to forward ports from the host to the containers. You can also use a reverse proxy like Traefik or Nginx Proxy.

Nginx Proxy example link: Run multiple Docker Compose projects on the same port using nginx-proxy — Learn Docker documentation