factoriotools / factorio-docker

Factorio headless server in a Docker container
https://hub.docker.com/r/factoriotools/factorio/
MIT License
888 stars 218 forks source link

Wrong port on mac #333

Open Na3blis opened 4 years ago

Na3blis commented 4 years ago

Hey, I'm trying to get the server running on an old MBP. I got the server running, but the port isn't correct so I'm unable to connect to it through the server browser.

 1.454 Info ServerMultiplayerManager.cpp:771: updateTick(0) changing state from(CreatingGame) to(InGame)
   1.463 Info ServerRouter.cpp:614: Asking pingpong servers (pingpong1.factorio.com:34197, pingpong2.factorio.com:34197, pingpong3.factorio.com:34197, pingpong4.factorio.com:34197) for own address
   1.464 Info UDPSocket.cpp:39: Opening socket for broadcast
   1.465 Error InterruptibleStdioStream.cpp:61: Got EOF on stdin; closing
   1.466 Info RemoteCommandProcessor.cpp:131: Starting RCON interface at IP ADDR:({0.0.0.0:27015})
   1.467 Info CommandLineMultiplayer.cpp:303: Maximum segment size = 100; minimum segment size = 25; maximum-segment-size peer count = 10; minimum-segment-size peer count = 20
   1.521 Info ServerRouter.cpp:497: Own address is IP ADDR:({my-ip:59150}) (confirmed by pingpong1)
   1.615 Info ServerRouter.cpp:497: Own address is IP ADDR:({my-ip:59150}) (confirmed by pingpong2)
   1.669 Info ServerRouter.cpp:497: Own address is IP ADDR:({my-ip:59150}) (confirmed by pingpong4)
   1.815 Info MatchingServer.cpp:114: Matching server game `7602394` has been created.
   1.838 Info ServerMultiplayerManager.cpp:703: Matching server connection resumed

I saw the guide mention changing the userland-proxy, but that doesn't appear to be an option on mac, based on https://stackoverflow.com/questions/44413816/how-to-disable-userland-proxy-for-docker-compose. Any suggestions on fixing this on the mac?

Additional Info: I created the server with:

docker run -d \
              -p 34197:34197/udp \
              -p 27015:27015/tcp \
              -v $HOME/.factorio/:/factorio \
              --name factorio \
              --restart=always \
              factoriotools/factorio

Running Docker Desktop 2.2.0.0 and docker engine 19.0.3.5

SuperSandro2000 commented 4 years ago

I think you need to forward the port somehwere in the UI. I don't own a mac so I can't help you with that to much.

Na3blis commented 4 years ago

I have my Mac firewall turned off. The server shows up in the public list, but does not show up in the lan list, even from the same computer. I am able to access my Plex server that's running on the same computer externally without having to change anything on the mac itself

cielo commented 3 years ago

Did you get a chance to find a work around with this issue? I cannot seem to find a way to update 'userland-proxy' config as well.

bplein commented 3 years ago

You won't normally see a dockerized Factorio server advertised on the LAN. This has to do with the way Docker networking works. Inside the docker container, there is a private address range. The factorio server THINKS it's on this network, and broadcasts inside that private network.

If you can run the container in network=host mode, then it attaches directly to the external network instead of having a private network. See issue #88

Na3blis commented 3 years ago

No, I was never able to resolve my issue. The problem is teh logs say it's hosting the game correctly at 34197. But then it logs that the port is 59150 or some other random port. Even using --net=host the server for some reason after correctly displaying the port 34197 later changes it to a different random port so nothing local, or public can connect to it.

1.136 Hosting game at IP ADDR:({0.0.0.0:34197}) ... 1.693 Info ServerRouter.cpp:525: Own address is IP ADDR:({myip:53937}) (confirmed by pingpong4)

bplein commented 3 years ago

I used to run this project's containers on macOS under Docker, but later I learned that a serious amount of performance is lost to the virtualization (Docker containers run in a Linux VM that doesn't do virtualization very well). I haven't run it that way in over a year AND I just gave your CLI a try and had the exact same thing going on with a Mac mini I have in my office.

If you aren't using this MBP fo anything else, I suggest loading Ubuntu on it, and then installing docker and running it that way. You'll get significantly more performance AND these issues go away.

bplein commented 3 years ago

And to be clear, in order to be sitting in your house and connect to it via the Multiplayer browser, your home router is going to need to be able to support "hairpin NAT". My pfSense does this and automatically "u-turns" the packets destined for the external IP and pushes them back through NAT. Of course you will need to set up a NAT rule on the UDP game port as well.

yasakbulut commented 3 years ago

The root cause of this issue is most certainly this: https://forums.factorio.com/viewtopic.php?f=49&t=35255

To summarise, docker manages a proxy to route traffic internally, and that causes the process inside the container get a random port. Example log line: Info ServerRouter.cpp:525: Own address is IP ADDR:({[REDACTED]:58289}) This causes the game to advertise its address with the wrong port on the public games list.

One can configure the Docker Daemon to route traffic using iptables instead of its own proxy; and that solves this issue.. However, this workaround does not work on macOS (nor Windows).

You can verify that you are having the issue that I'm describing by connecting to your server directly by entering its IP/port -- If that works, you can be sure that your port forwarding settings are not the issue here.

I have the same issue, and I worked around that by using a DDNS service to map my public IP to a domain name, so that my server can be accessed at [domain name]:34197.

As far as I understand, this issue needs one of the following to be resolved:

  1. Docker for Mac having support for the userland-proxy flag. (very unlikely)
  2. The factorio server binary adding support for passing in the port number via a startup flag, and using that port number instead of the autodetected one. (less unlikely, but still)

Maybe this project's maintainers have a communication channel with factorio devs, so that a conversation around point #2 can be started?

tl;dr: hosting public games on macOS is not possible.

PyroSA commented 3 years ago

So is the tl;dr that you CANNOT host this image on Windows or Mac?

I tried on both, and got the same invalid remote port.

I was also unable to connect to 34197 on either the local or remote ports, so the problem might lie elsewhere?

yasakbulut commented 3 years ago

@PyroSA there might be another additional issue at play in your case, so many moving parts when networking is involved :)

just to clarify my tl;dr, you can host public games, but no one will be able to connect to them through the public game directory in-game. in fact, i'm hosting a server for my friends on my Mac mini, but they have to connect using my IP/port.

ZCube commented 1 year ago

How about use https://github.com/ZCube/factorio-port-fixer.

According to https://www.factorio.com/blog/post/fff-143 it is the pingpong server that determines the initial port. Therefore, you can use the port you want by simply replacing that server. ( Currently port 34197 is fixed and port forwarding is required. )

Epp-code commented 1 year ago

@ZCube that is super helpful - thank you for making and sharing it! If I may be so bold, it would help to flesh out the documentation a bit. I didn't initially understand the difference between local and remote modes or whether I had to edit the hosts file, etc. I eventually pieced it together and it's working flawlessly, though!

Also, if WUBE ever reads this: please just give us a command line option to explicitly set our dedicated port without using the pingpong servers. Would save a lot of pain in cases like this.