I am new to docker, and I want to deploy two minecraft server container using docker compose. I have a server running docker engine on which I want to deploy those, and my desktop pc running docker compose. I have created a docker context to deploy to the server using my desktop.
I have two different compose files which specify different settings for the servers.
#server1.yml
version: '3.8'
services:
mc:
image: itzg/minecraft-server
container_name: server1
tty: true
stdin_open: true
ports:
- '25565:25565'
environment:
EULA: true
TYPE: FABRIC
VERSION: 1.20.1
SERVER_NAME: server1
volumes:
- /data/server1:/data
and
#server2.yml
version: '3.8'
services:
mc:
image: itzg/minecraft-server
container_name: server2
tty: true
stdin_open: true
ports:
- '25565:25565'
environment:
EULA: true
TYPE: FORGE
VERSION: 1.18.2
SERVER_NAME: server2
volumes:
- /data/server2:/data
When I run docker compose -f .\server1.yml up -d, the container runs on my server, and I have no problem. However, when I run docker compose -f .\server2.yml up -d to have both running at the same time, it replaces server1. What I want is a setup with which I can run those minecraft server independently of another. How do I do that? Also, do I need docker compose on my server, or is the engine enough?
>Solution :
Rename your docker-compose services in both server1.yml and server2.yml to give them distinct names. For example, you can change mc to server1_mc in server1.yml and server2_mc in server2.yml.
server1.yml:
version: '3.8'
services:
server1_mc: # Changed service name to server1_mc
image: itzg/minecraft-server
container_name: server1
tty: true
stdin_open: true
ports:
- '25565:25565'
environment:
EULA: true
TYPE: FABRIC
VERSION: 1.20.1
SERVER_NAME: server1
volumes:
- /data/server1:/data
server2.yml
version: '3.8'
services:
server2_mc: # Changed service name to server2_mc
image: itzg/minecraft-server
container_name: server2
tty: true
stdin_open: true
ports:
- '25566:25565' # Change the external port to 25566 to avoid conflicts
environment:
EULA: true
TYPE: FORGE
VERSION: 1.18.2
SERVER_NAME: server2
volumes:
- /data/server2:/data
When starting each server, use a different external port to map to the Minecraft server’s internal port. In the modified server2.yml, we changed the external port from 25565 to 25566. This way, you can access the second server by connecting to your server’s IP address with port 25566.
To start both Minecraft servers, run the following commands from your desktop PC:
docker-compose -f server1.yml up -d
docker-compose -f server2.yml up -d
This will start both Minecraft servers independently, and they should run concurrently without replacing each other. You can access them by connecting to your server’s IP address using the respective external ports you defined in the docker-compose files.