itzg / docker-minecraft-server

Docker image that provides a Minecraft Server that will automatically download selected version at startup
https://docker-minecraft-server.readthedocs.io/
Apache License 2.0
9.55k stars 1.56k forks source link

Ability to run two minecraft server instances on the same machine #1243

Closed davidmoshal closed 2 years ago

davidmoshal commented 2 years ago

Enhancement Type

Not sure

Describe the enhancement

Not sure if this is already supported. If so, the request is for documentation on how to do it.

So far I've discovered that just running separate containers doesn't work because the second server kills the first server. Even with different:

Server 1 docker-compose.yml:

services:
  mc:
    image: itzg/minecraft-server
    ports:
      - 25565:25565
    environment:
      MOTD: "lunar-one"
      EULA: "TRUE"
      ENABLE_RCON: "true"
      RCON_PASSWORD: ${RCON_PASSWORD}
      RCON_PORT: 28016
      restart: always
    volumes:
    - /minecraft/docker-compose/data:/data

Server 2 docker-compose.yml

services:
  mc:
    image: itzg/minecraft-server
    ports:
      - 27777:25565
    environment:
      MOTD: "ben-one"
      EULA: "TRUE"
      ENABLE_RCON: "true"
      RCON_PASSWORD: ${RCON_PASSWORD}
      RCON_PORT: 28616
      restart: always
    volumes:
    - /ben/minecraft/docker-compose/data:/data

Here is the log from the first server when the second server is started:

2022-01-02T22:37:15.769Z    ERROR   mc-server-runner    Failed to stop using rcon-cli   {"error": "exit status 1"}
2022-01-02T22:37:15.769Z    INFO    mc-server-runner    Sending 'stop' to Minecraft server...
2022-01-02T22:37:15.769Z    INFO    mc-server-runner    Waiting for completion...

So, something in the second server kills the first server.

davidmoshal commented 2 years ago

SOLVED! The solution was to give the servers different container names, eg:

Megasware128 commented 2 years ago

I believe a different folder name where the docker-compose file is stored should also help

Marshin386 commented 2 years ago

davidmoshal, could you share how you got 2 Minecraft servers running on the same docker (in separate containers). what settings did you end up using to make it work? I'm still getting a port conflict (port wont bind) when I try to start the second minecraft server

itzg commented 2 years ago

@Marshin386 just change the host (left-side) part of the port mapping to choose unique host ports such as 25566 on mc2:

version: "3"

services:
  mc1:
    image: itzg/minecraft-server
    ports:
      - "25565:25565"
    environment:
      EULA: "TRUE"
    volumes:
      - ./mc1-data:/data
  mc2:
    image: itzg/minecraft-server
    ports:
      - "25566:25565"
    environment:
      EULA: "TRUE"
    volumes:
      - ./mc2-data:/data
Marshin386 commented 2 years ago

Stack from first server


version: "2" services: minecraft-server: image: itzg/minecraft-server:java17 container_name: MC118 network_mode: host environment:

Stack from second server (that won't start because of a port conflict) see attached copy of docker log from second server trying to start


version: "2" services: minecraft-server2: image: itzg/minecraft-server:java17 container_name: minecraft2 network_mode: host environment:

docker log copy second server.txt

itzg commented 2 years ago

@Marshin386 network_mode: host -- that's your problem

Marshin386 commented 2 years ago

Thank you, took me a few to realize I just needed to remove the line (not necessary to run)

able to now run more than one at a time now.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Please add a comment describing the reason to keep this issue open.