itzg / docker-rcon-web-admin

A Docker image that runs rcon-web-admin
MIT License
92 stars 18 forks source link

Connect to server run on a different Docker network #10

Closed MyBlackMIDIScore closed 3 years ago

MyBlackMIDIScore commented 3 years ago

On my Docker installation I had already 2 Minecraft servers using your image before I installed this rcon image. So I made it in a completely different docker-compose file so it is not connected directly with the server as in your example. So there I tried instead of giving it the container name of the server, to type out the server IP address, which apparently did not work (it cannot find the server). Is there any workaround to this without me inserting the image into both docker-compose files for both my servers? I want to keep all of it in one web interface. I will attach my docker-compose file below. Thanks in advance!

version: '3' services: web: image: itzg/rcon environment: RWA_USERNAME: admin RWA_PASSWORD: obviouslyremovedtheoriginal RWA_ADMIN: "TRUE" RWA_RCON_HOST: mc.mbms.me RWA_RCON_PASSWORD: obviouslyremovedtheoriginaltoo ports:

  • 4326:4326
  • 4327:4327
itzg commented 3 years ago

One of the things docker compose does for you is create a default network for each compose project (aka directory). So, first you'll need to retrieve the name of the network your minecraft server compose created, which is named ${PROJECT}_default where $PROJECT is by default the name of the directory containing the compose file. Use docker network ls and find the one that it would be. In my case, it was mc-project_default.

So, in my rcon web compose file I did two things:

With that I can reference the "mc" container's internal hostname in RWA_RCON_HOST. (FYI one reason your attempt didn't work is because you didn't and shouldn't have the rcon port 25575 exposed at mc.mbms.me)

So the complete compose file is:

version: '3.3'

services:
  web:
    image: itzg/rcon
    environment:
      RWA_USERNAME: admin
      RWA_PASSWORD: admin
      RWA_ADMIN: "TRUE"
      # is referring to the hostname of 'mc' in the mc-project network
      RWA_RCON_HOST: mc
      # needs to match the password configured for the container, which is 'minecraft' by default
      RWA_RCON_PASSWORD: minecraft
    ports:
      - 4326:4326
      - 4327:4327
    networks: 
      - other

networks: 
  other:
    external: true
    name: mc-project_default

and for completeness the "mc-project/docker-compose.yml" file:

version: '3.3'

services:
  mc:
    image: itzg/minecraft-server
    ports:
      - 25565:25565
    environment:
      EULA: "TRUE"
MyBlackMIDIScore commented 3 years ago

Thanks for your reply! I tried out the external network settings you suggested and now I don't get the "cannot connect" message anymore. Although when I select "minecraft" from the list it doesn't show anything below it (see attached image).

image

At first I though that this was caused by the mc-backup image that I am using at the same time, not allowing more RCON instances at once. But weirdly enough when I disabled it and restarted the server, it was still not showing any settings.

I will attach my Docker Compose files below again.

Thanks in advance!

Server:

version: '3.7'
services:
  ShulkerCraft:
    image: itzg/minecraft-server:adopt11
    environment:
      EULA: "true"
      TYPE: PAPER
      VERSION: LATEST
      ENABLE_AUTOPAUSE: "FALSE"
      INIT_MEMORY: "512M"
      MAX_MEMORY: "24G"
      ENABLE_RCON: "true"
      RCON_PASSWORD: "minecraft"
      RCON_PORT: 25575
    ports:
      - 25565:25565
    volumes:
      - ./data:/data
    networks:
      - Minecraft
  ShulkerCraft-Backup:
    image: itzg/mc-backup
    environment:
      BACKUP_INTERVAL: "24h"
      BACKUP_NAME: "ShulkerCraft_Backup"
      PRUNE_BACKUPS_DAYS: 10
      RCON_HOST: "localhost"
      RCON_PORT: 25575
      RCON_PASSWORD: "minecraft"
      BACKUP_METHOD: "tar"
    volumes:
    - ./data:/data:ro
    - /mnt/md0/MinecraftBackups:/backups
    network_mode: "service:ShulkerCraft"

networks:
  Minecraft:

RCON:

version: '3.7'

services:
  web:
    image: itzg/rcon
    environment:
      RWA_USERNAME: admin
      RWA_PASSWORD: admin
      RWA_ADMIN: "TRUE"
      RWA_RCON_HOST: ShulkerCraft
      RWA_RCON_PASSWORD: minecraft
    ports:
      - 4326:4326
      - 4327:4327
    networks:
    - other

networks:
  other:
    external: true
    name: shulkercraft_Minecraft
itzg commented 3 years ago

Yeah, that part is not very intuitive. You have to add a widget and "Console" is really the only one that makes sense:

image

MyBlackMIDIScore commented 3 years ago

Oh, this makes sense. I didn’t notice this. It seems to work perfectly fine now. Thanks a lot for the help, appreciate it!