Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to run multiple docker container from one image using compose

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading