karlrees/docker_bedrockserver

docker on MacOS can't use --network="host"

Shawnfreebern opened this issue · 3 comments

According to docker docs:

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac [...]

The result is that you have to specify which ports to publish on MacOS. For a remote server you can (possibly) get away with publishing only your chosen server port (19132) but for LAN games minecraft opens a second randomly chosen port which you need to publish, but can't because you don't know the number when you start the container.

Docker has a --publish-all function but it doesn't seem to work:

  • it appears to only publish ports opened early in the container start process, and the LAN port is opened a bit later
  • both TCP and UDP are required and it looks like --publish-all doesn't get that done
  • it assigns known ports to randomly selected higher ports, which further complicates remote server access

My solution at present is to artificially limit which random ports are available, and then specifically publish all port options for both TCP and UDP:

docker run --sysctl net.ipv4.ip_local_port_range="39132 39133" -p 19132:19132 -p 19132:19132/udp -p 39132:39132 -p 39132:39132/udp -p 39133:39133 -p 39133:39133/udp --name="minecraft" etc

Someone will hopefully find a better way to do this (I am not a docker, minecraft, or mac networking expert) but until that's discovered this might be helpful to other mac users.

Thanks for the tip. I don't have a Mac to test on. Best thing I can do, unless someone else wants to chime in, is add your tip to the ReadMe.

I'm not sure how much more time I'll spend on this, so that's probably a decent solution. If you'd like I can fork / update / pull req so any future mac progress will have a clearer path.

Side note, if you do update the ReadMe there's one instance of /srv/mcpeserver that should probably be updated to /srv/bedrockserver.

Sure, go ahead.

Just a thought--I wonder if it would be helpful to add a shell script and/or docker-compose file specifically to setup the container(s) on MacOS, or if the setup script I recently added could be made generic enough to work with MacOS as well.