Hi there, I am running a docker container on WSL 2 which I want to connect to from my LAN.
The docker container gets by default ip 172.17.0.x, if I define manually an ip (such as “–ip 192.168.3.100” my LAN) the containers cannot communicate with my lan devices.
I was thinking to create a port forwarding between the host (Windows 10) and the container.
Is there a more elegant way to accomplish that? Note that I will also need other containers to talk each others.
The most elegant way is not to play around with IP addresses. Let Docker do the work. A container can automatically access all LAN devices. Example (from WSL2):
$ docker container run --rm debian ping -c 1 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=37 time=2.26 ms
If this doesn’t work the traffic is probably blocked by your firewall.
To communicate between containers start them with a docker-compose file, they will automatically share a private network and can access each other using the service names.
docker run -d -p 192.168.3.100:80:80 docker/getting-started
map your IP alias and port 80 of the host to port 80 in the container
-p 192.168.3.100:80:80
Hello, I have the same issue as the topicstarter, and while I’m sorry for necroing this post, it would still seem appropriate since the problem is really hard to solve and I found no answers to it yet ;(
So, I’ve tried your advice on the following setup:
Windows 11
Docker Desktop
WSL2 (Docker Desktop recommended me to use it so I just accepted the proposal on install of Docker Desktop)
I got a container which is a dockerized version of Satisfactory Dedicated Server from github, which I want to share with my friends over the internet.
I have a publicly visible static ip, and knowledge how to portforward things on the router.
My Win11 PC has an IP of 192.168.0.2 on my local network.
My docker container has the following “docker run” command structure :
docker run --hostname=satisfactory-server --mac-address=[MY_MAC_ADDRESS] --env=MAXPLAYERS=4 --env=PGID=1000 --env=PUID=1000 --env=STEAMBETA=false --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=USER=root --env=HOME=/root --env=LANG=en_US.UTF-8 --env=LANGUAGE=en_US:en --env=AUTOSAVENUM=5 --env=DEBIAN_FRONTEND=noninteractive --env=DEBUG=false --env=DISABLESEASONALEVENTS=false --env=GAMECONFIGDIR=/config/gamefiles/FactoryGame/Saved --env=GAMESAVESDIR=/home/steam/.config/Epic/FactoryGame/Saved/SaveGames --env=LOG=false --env=MAXOBJECTS=2162688 --env=MAXTICKRATE=30 --env=MULTIHOME=:: --env=SERVERGAMEPORT=7777 --env=SERVERSTREAMING=true --env=SKIPUPDATE=false --env=STEAMAPPID=1690800 --env=TIMEOUT=30 --env=VMOVERRIDE=false --env=VERSION=1.9.5 --volume=C:\Users\username/satisfactory-server:/config --network=bridge --workdir=/config -p 7777:7777 -p 7777:7777/udp --restart=unless-stopped --label='org.opencontainers.image.ref.name=ubuntu' --label='org.opencontainers.image.version=22.04' --label='version=1.9.5' --runtime=runc --memory="8589934592" --memory-reservation="4294967296" -d wolveix/satisfactory-server:latest
It runs and starts up normally, I can launch the game and add it to my Server Manager there using 127.0.0.1:7777 address. It connects and I can join it.
But nothing can connect to it from my 192.168.0.x network (lan) and nothing can connect to it from the internet (I’ve portforwarded the port 7777 to the outside).
So, I’ve gone to the google and stumbled upon this topic, I’ve seen your advice and example command and decided to try it out:
docker run --hostname=satisfactory-server --mac-address=[MY_MAC_ADDRESS] --env=MAXPLAYERS=4 --env=PGID=1000 --env=PUID=1000 --env=STEAMBETA=false --env=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env=USER=root --env=HOME=/root --env=LANG=en_US.UTF-8 --env=LANGUAGE=en_US:en --env=AUTOSAVENUM=5 --env=DEBIAN_FRONTEND=noninteractive --env=DEBUG=false --env=DISABLESEASONALEVENTS=false --env=GAMECONFIGDIR=/config/gamefiles/FactoryGame/Saved --env=GAMESAVESDIR=/home/steam/.config/Epic/FactoryGame/Saved/SaveGames --env=LOG=false --env=MAXOBJECTS=2162688 --env=MAXTICKRATE=30 --env=MULTIHOME=:: --env=SERVERGAMEPORT=7777 --env=SERVERSTREAMING=true --env=SKIPUPDATE=false --env=STEAMAPPID=1690800 --env=TIMEOUT=30 --env=VMOVERRIDE=false --env=VERSION=1.9.5 --volume=C:\Users\username/satisfactory-server:/config --network=bridge --workdir=/config -p 192.168.0.2:7777:7777 -p 192.168.0.2:7777:7777/udp --restart=unless-stopped --label='org.opencontainers.image.ref.name=ubuntu' --label='org.opencontainers.image.version=22.04' --label='version=1.9.5' --runtime=runc --memory="8589934592" --memory-reservation="4294967296" -d wolveix/satisfactory-server:latest
and got this error:
(HTTP code 500) server error - Ports are not available: exposing port TCP 192.168.0.2:7777 -> 127.0.0.1:0: listen tcp 192.168.0.2:7777: bind: An attempt was made to access a socket in a way forbidden by its access permissions.
Did I do something wrong? Any help resolving this issue will be greatly appreciated
-p 192.168.0.2:7777:7777 -p 192.168.0.2:7777:7777/udp
This is not going to work with Docker Desktop, as the docker engine runs in a utility vm, which does not know about your Windows host’s ip.
When -p <host-port>:<container-port>
is used, docker binds ports to -p 0.0.0.0:<host-port>:<container-port>
. 0.0.0.0
== all host ips. Thus, `-p :: acts as a restriction which host-ip to bind.
Your problem is most likely that the application inside the container binds its port on the localhost ip 127.0.0.1, instead to 0.0.0.0.
You should start using docker compose, as it makes life way easier. You can use https://www.composerize.com to convert your docker run
command to a compose file.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.