itzg / docker-minecraft-bedrock-server

Containerized Minecraft Bedrock Dedicated Server with selectable version
MIT License
1.14k stars 218 forks source link

Dockerfile line 16 hard-coded port expose causing issues with multi-instances #216

Open ncrosty58 opened 2 years ago

ncrosty58 commented 2 years ago

I am running 3 instances of the minecraft server in containers and this part of the docker file is causing some strange problems.

EXPOSE 19132/udp

Can this be removed?

itzg commented 2 years ago

At container creation time the host port mapping should be adjusted to avoid host level conflicts. The container side port, the one in the EXPOSE, is within the container where each container has a distinct networking namespace.

Here's a tutorial on running multiple instances

https://github.com/itzg/docker-minecraft-bedrock-server/issues/147#issuecomment-835415300

ncrosty58 commented 2 years ago

Alright I got it working with the servers tab. I had to use all non-standard ports in my docker config.yaml image

Now all of my servers are reporting a ping and the number of players. Hope this helps someone else. Nothing shows up in the LAN servers under friends with this configuration, however.

image

itzg commented 2 years ago

Good to close the issue and PR?

ncrosty58 commented 2 years ago

would be way better if the port was definable in the yaml file vs hard coded in the dockerfile. I still have that default port exposed for no reason because I can't set it up how I want it in my yaml.

itzg commented 2 years ago

That is not hardcoding the host port, just advertising the container port.

https://docs.docker.com/engine/reference/builder/#expose

How are you doing your port mapping? You can put whatever you want there and the EXPOSEd advertisement gets ignored.

ncrosty58 commented 2 years ago

Here is an example docker-compose file of mine for "cos2" server above. Based on some testing it looks like this server is always listening on port 19132 no matter what the settings are. I just like the option to make a straightforward adjustment to my yaml files to control what ports are listening. having that export in the dockerfile threw me for a loop.

version: '3.4'

services:
  bds:
    container_name: cos_mc_2
    image: itzg/minecraft-bedrock-server
#    image: nc_mcimage
    environment:
      EULA: "TRUE"
      GAMEMODE: survival
      DIFFICULTY: normal
      ONLINE_MODE: "true"
      SERVER_PORT: 19134
      SERVER_PORT_V6: 19135
      SERVER_NAME: "Cosmos Lab 2"
    ports:
      - 19134:19134/tcp
      - 19134:19134/udp

    stdin_open: true
    tty: true
    volumes:
      - /usr/share/mc_svr_2:/data
itzg commented 2 years ago

Based on some testing it looks like this server is always listening on port 19132

I wouldn't expect that. Can you provide output/screenshots of that finding?

ncrosty58 commented 2 years ago

here is the startup log with that same yaml file above image

itzg commented 2 years ago

That is not influenced by the EXPOSE and is beyond my control. Have you built the image with your change to test?

ncrosty58 commented 2 years ago

I did try my image with that line taken out. the results are functionally equivalent. So I just switched back to your image for updatability.

In the end I agree its not the docker container here that is the real problem. it seems that the mojang server is doing some really unfortunate port assignment/usage. Lots of bug reports on their JIRA about it.

My use case is working as long as I don't use the default port for any of my docker containers - servers are reporting and working good. Friends are able to add them in 'external servers' tab and its all good. Does not work for the LAN use case.

bb-Ricardo commented 11 months ago

Hi,

running into similar issues. In newer versions the log output seems to be more precise:

home-mc-server-abc-1  | [2023-11-01 20:52:00:791 INFO] Content logging to console is enabled.
home-mc-server-abc-1  | [2023-11-01 20:52:02:894 INFO] Opening level 'worlds/abc/db'
home-mc-server-abc-1  | [2023-11-01 20:52:03:146 INFO] IPv4 supported, port: 60603: Used for gameplay
home-mc-server-abc-1  | [2023-11-01 20:52:03:146 INFO] IPv6 not supported
home-mc-server-abc-1  | [2023-11-01 20:52:03:173 INFO] Server started.
home-mc-server-abc-1  | [2023-11-01 20:52:03:173 INFO] ================ TELEMETRY MESSAGE ===================
home-mc-server-abc-1  | [2023-11-01 20:52:03:173 INFO] Server Telemetry is currently not enabled.
home-mc-server-abc-1  | [2023-11-01 20:52:03:173 INFO] Enabling this telemetry helps us improve the game.
home-mc-server-abc-1  | [2023-11-01 20:52:03:173 INFO]
home-mc-server-abc-1  | [2023-11-01 20:52:03:173 INFO] To enable this feature, add the line 'emit-server-telemetry=true'
home-mc-server-abc-1  | [2023-11-01 20:52:03:173 INFO] to the server.properties file in the handheld/src-server directory
home-mc-server-abc-1  | [2023-11-01 20:52:03:173 INFO] ======================================================
home-mc-server-abc-1  | [2023-11-01 20:52:03:190 INFO] IPv4 supported, port: 19132 used for LAN discovery
home-mc-server-abc-1  | [2023-11-01 20:52:03:190 INFO] IPv6 not supported

Also the server port is set to 60603 it seems to open the default port 19132 additionally. enable-lan-visibility=false

Netid     State      Recv-Q     Send-Q         Local Address:Port          Peer Address:Port     Process
udp       UNCONN     0          0                    0.0.0.0:47318              0.0.0.0:*         users:(("bedrock_server-",pid=10,fd=10))
udp       UNCONN     0          0                    0.0.0.0:60603              0.0.0.0:*         users:(("bedrock_server-",pid=10,fd=9))
udp       UNCONN     0          0                 127.0.0.11:41177              0.0.0.0:*
tcp       LISTEN     0          128               127.0.0.11:36894              0.0.0.0:*         ino:847413937 sk:1 <->

enable-lan-visibility=true

Netid     State      Recv-Q     Send-Q         Local Address:Port           Peer Address:Port     Process
udp       UNCONN     0          0                    0.0.0.0:60603               0.0.0.0:*         users:(("bedrock_server-",pid=9,fd=10))
udp       UNCONN     0          0                 127.0.0.11:48803               0.0.0.0:*
udp       UNCONN     0          0                    0.0.0.0:19132               0.0.0.0:*         users:(("bedrock_server-",pid=9,fd=11))
tcp       LISTEN     0          128               127.0.0.11:37134               0.0.0.0:*         ino:847440340 sk:1 <-> 
itzg commented 11 months ago

Thank you for the research @bb-Ricardo , but I'm not sure if that indicates this is an image problem or a bedrock problem. I'm still assuming the latter since I don't know how bedrock could "sense" what port is EXPOSE'd.

With that said, I really don't feel strongly about keeping the EXPOSE in the Dockerfile, so I can remove that and see if that fixes the issue.

bb-Ricardo commented 11 months ago

It actually doesn't matter either way. As you wrote, if you define the port explicitly via -p then the EXPOSE is completely ignored. If you don't define a port via -p then the EXPOSE definition will be used to export to port.

I'm also running multiple servers via docker and they don't show up properly on the friends tab. I'm using manymine to solve this but it is also not fully solving the issue at the moment as it seems that the udp package to discover instances on the local network seems to disappear somehow. Currently investigating why.

Further more in regards of exposing the port for lan visibility. It seems that the bedrock server just picks a random port instead of the default 19132 to "disable" the visibility. Developers couldn't be bothered to not even start the port properly 🤨