r/docker • • 14d ago

Server is only accessible on host mode or when using container addresses

SOLVED, see here: https://www.reddit.com/r/docker/s/92gXpeXGTe. This post will self-destruct eventually.

Here is my docker-compose.yaml

name: tactics

services:
  server:
    container_name: server
    build:
      dockerfile: server.Dockerfile
    ports:
      - "8000:8000"
    networks:
      - backend

networks:
  backend:
    driver: bridge

and my server.Dockerfile

debian:bookworm-slim
ENV HOME=/root
ENV PATH="$PATH:$HOME/bin"
WORKDIR $HOME/bin
COPY Server.x86_64 Server.x86_64 ./
ENTRYPOINT ["/root/bin/Server.x86_64", "--headless", "--verbose"]

I create the Godot Server on a port, and create a Godot Client that connects to the same port.

If I use an address that refers directly to the container (the one shown by this https://stackoverflow.com/a/20686101) the connection is successful.

Or if I rewrite the compose to use host network mode, the connection is successful.

If I use any other address (0.0.0.0,, localhost, my public IP, my private IP), it times out.

Some suggestions have been to bind to 0.0.0.0, but I am not sure the effects of that or how it would be done in compose.

I am on an Ubuntu machine. I suppose I could also deploy to some cheap server farm. Any help is appreciated, including "don't worry about it and just use host / direct container address, here's why".

EDIT: btw I seemingly enabled br_netfilter as it was disabled, as suggested here: https://stackoverflow.com/a/60897412. Might be relevant. Didn't help though.

4 Upvotes

10 comments sorted by

5

u/encbladexp 14d ago

Some suggestions have been to bind to 0.0.0.0, but I am not sure the effects of that or how it would be done in compose.

If your compose contained only 1234:1234 this means you already bound your service to 0.0.0.0 (from a container perspective).

And of course, a service within the container needs to listen on 0.0.0.0, so it could be forwarded.

And we talk about Docker Engine on your Ubuntu box, not this horrible Docker Desktop mess, right?

1

u/Disastrous-Spare3907 14d ago

Yes it's Docker Engine. Docker Desktop seemed hard to install on Linux.

1

u/ahumannamedtim 14d ago

You mapped a host port too right? Like 80:80 for example?

Censoring the port isn't really necessary. Tools like nmap that can scan for open ports anyway, it's not really a secret.

1

u/Disastrous-Spare3907 14d ago

Ah. Port is "8000:8000". Pretty sure "8000" has same effect though. Unless there's some reason it needs to be 80?

1

u/ahumannamedtim 14d ago

Right, the port number doesn't really matter as long as there's two numbers, one for the host port and one for the container port. 80 is reserved for http.

Your server is also listening to port 8000?

1

u/Disastrous-Spare3907 14d ago

Pretty sure it is yes, since

  1. the connection works when I use the container address
  2. in Godot I called create_server(8000,1) on the server executable (which yes, is running and does log to docker console)

1

u/ymgymg 14d ago

Godot's multiplayer peer uses ENet, which is UDP, and "8000:8000" in compose only publishes TCP. Change it to "8000:8000/udp" and it should work without host mode.

1

u/Disastrous-Spare3907 14d ago

Right, and network_mode=host doesn't require port publishing. Works great, Thanks!

1

u/dadarkgtprince 14d ago

Is your backend network external?

0

u/fletch3555 Mod 14d ago

It's shown in the OP. Not "internal", and not defined external to the compose file, so it's definitely "external" (unless they cut out relevant details)