Client unable to connect to server when run as docker container

Hi,

I have posted on ( Unity clients can’t connect to server on Docker container - Unity Forum ) but it seems like an old thread that has been resolved, maybe I should make a separate one. I have the the following problem.

My machine is running Windows 11, with Unity at version 2021.2.12f1.

I have built a Dedicated Server set to Linux. In this build, the NetworkManager uses UnityTransport found in the Netcode for GameObjects package. In the UnityTransport, I have set the server to use

Address = 127.0.0.1
Port = 9041
Server Listen Address = 127.0.0.1

My client settings are as follows:

Address = 127.0.0.1
Port = 9041
Server Listen Address = 127.0.0.1

When I run this on Windows Subsystem for Linux (WSL) terminal, the client version of my game can connect to the server. However, when I package the server into a docker image and run it as a container in docker, the client is unable to connect to the docker container. The docker network settings are as follows:

0.0.0.0 : 9041 / 9041 tcp
0.0.0.0 : 9041 / 9041 udp

Since 0.0.0.0 mean any address, this should work right? I tested it with the standard nginx just to check if using 0.0.0.0 works, it does work when I tried to reach 127.0.0.1 : 80 on my browser.

I intend to run the containerized server on a commercial cloud service, and would be good if I do not have to hard-code the ip address into the server.

In short, my client is able to connect to the server if I run the server directly from terminal, but unable to connect if i run the server as a docker container.

Your server’s listen address should be set to 0.0.0.0 so that it accepts any connection. By setting it to 127.0.0.1 the server will only accept connections from itself (so only applications in the container).

Hi Luke,

Thanks! this worked! For future reference, I have set the server to use

Address = 127.0.0.1
Port = 9041
Server Listen Address = 0.0.0.0

My client settings are as follows:

Address = 127.0.0.1
Port = 9041
Server Listen Address = Doesn’t matter.

1 Like