I made a deal with my son where in, if he built a fully-working, 3 way traffic light in minecraft, I would host him his own minecraft server so he and his friends could play anytime. He upheld his end of the bargain, so it's my turn.
In order to keep this thing boxed in, and trying to keep it both simple and cheap for his friends (mojang auth requires paid mojang account), I am using a simple VPN container with shared users/pass/psk – he can just give it to his friends.
The problem: This works fine if, when they connect they set the server to be the ip address of the container on the docker network. Problem is, that changes every time I restart. I need a DNS resolver so that the server name is always minecraft
when on the vpn. The DNS that comes with this VPN uses public DNS, which I can override, but when I dig
while on the vpn container (but not on the vpn iself) I get an ip address I didn't expect and one I simply can't predict. Thus, I don't know if/how I should override it. I have read the documentation on docker's website and I have also considered using dnsmasq as a forwarder. Details below.
docker-compose.yml
version: '3.3'
services:
minecraft:
build:
context: .
restart: always
hostname: minecraft
volumes:
- world:/game/world
vpn:
image: hwdsl2/ipsec-vpn-server
environment:
- VPN_DNS_SRV1=127.0.0.11
restart: always
hostname: vpn
ports:
- 500:500/udp
- 4500:4500/udp
privileged: true
volumes:
world:
terminal debug (off vpn):
[ec2-user@ip-172-31-25-185 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
608165ea8236 hwdsl2/ipsec-vpn-server "/opt/src/run.sh" 2 days ago Up 2 days 0.0.0.0:500->500/udp, 0.0.0.0:4500->4500/udp mcft_vpn_1
075f6313ae9d mcft_minecraft "java -Xms1024M -jar…" 2 days ago Up 2 days 25565/tcp mcft_minecraft_1
[ec2-user@ip-172-31-25-185 ~]$ docker exec -it 608165ea8236 /bin/bash
root@vpn:/opt/src# dig minecraft
; <<>> DiG 9.10.3-P4-Debian <<>> minecraft
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29390
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;minecraft. IN A
;; ANSWER SECTION:
minecraft. 600 IN A 172.20.0.2
;; Query time: 0 msec
;; SERVER: 127.0.0.11#53(127.0.0.11)
;; WHEN: Mon Jul 08 14:45:41 UTC 2019
;; MSG SIZE rcvd: 52
root@vpn:/opt/src#
Best Answer
Probably the simplest solution would be to assign a static IP address to the
minecraft
container. You can see how to do that in https://stackoverflow.com/questions/27937185/assign-static-ip-to-docker-container (refer to the answer which usesdocker-compose
, since that's what you're using).