0

I am running netmaker which is a wireguard mesh VPN service on a Docker container, and I need port 9981 to be reachable from the Docker container, so that I can access port 9981 via my Wireguard WAN.

Port 9981 is open on the VPS on which Netmaker is hosted, but isn't reachable from within the Docker container. I have been trying to no avail to get this right, and I'm now at my wits end.

I was advised to add this line to my docker-container file which has just caused error after error -

PORT_FORWARD_SERVICES="127.0.0.1:9981:9981"

Please can someone assist.

Artur Meinild
  • 21,605
  • 21
  • 56
  • 89
Paul Barnett
  • 1
  • 1
  • 1
  • Please specify which instructions you used to start the container (and include them in your post). It's purely guessing from my side, until you provide some more details. – Artur Meinild Jun 14 '22 at 05:57
  • Imo, this is a docker question and not related to Ubuntu. Check [this](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) on stackoverflow for an answer. – pLumo Jun 14 '22 at 07:04
  • I don't see why [Docker questions](https://askubuntu.com/questions/tagged/docker) would be off-topic? – Artur Meinild Jun 14 '22 at 07:31

1 Answers1

0

Did you try the Docker documentation? Port forwarding is a pretty standard feature in Docker.

In a normal CLI syntax you add:

-p <host-port>:<container-port>

This is an example command that maps port 443:

docker run -d \
  --name=nextcloud \
  -e PUID=1000 \
  -e PGID=1000 \
  -e TZ=Europe/London \
  -p 443:443 \
  -v /path/to/appdata:/config \
  -v /path/to/data:/data \
  --restart unless-stopped \
  lscr.io/linuxserver/nextcloud:latest

So you need to add -p 9981:9981 to the command you use to run your container.

There is also a similar syntax if you use Docker Compose (but since you didn't specify I assume this isn't the case).

Artur Meinild
  • 21,605
  • 21
  • 56
  • 89
  • I think OP needs to connect to a port on the host from inside the container, so he needs to [add `--network host` or `--add-host ...`](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) – pLumo Jun 14 '22 at 07:04
  • In that case, the title is completely misleading - I'll leave my answer as long as the title says "port forward from my host to docker container" - but I'll remove it if it's no longer relevant. – Artur Meinild Jun 14 '22 at 07:10