Skip to content

Easily deploy and manage Minecraft servers with this Docker setup. This project streamlines the process of running Minecraft servers, including various modpacks, by leveraging Docker's benefits of isolation, portability, and consistency. Simplify your server management and ensure a consistent environment across different machines.

License

Notifications You must be signed in to change notification settings

FilipRokita/minecraft-server-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Minecraft Server in Docker

Table of Contents

Overview

This project provides a Docker setup for running a Minecraft server. It simplifies the process of setting up and managing Minecraft servers by using Docker, making it easier to deploy and maintain different Minecraft server versions and modpacks.

Why Use Docker for Minecraft Server?

Running a Minecraft server in a Docker container offers several advantages:

  • Isolation: Each server runs in its own environment, reducing conflicts with other software.
  • Portability: Easily move your server setup between different machines.
  • Consistency: Ensure that the server runs in the same environment every time, reducing issues related to system differences.

Prerequisites

  • Git and Docker Engine installed on your machine.
  • Basic familiarity with Docker commands.

Tested On

Ubuntu Server 22.04 with:

Installation

  1. Clone the Repository

    git clone https://github.com/FilipRokita/minecraft-server-docker
  2. Rename the Repository Folder

    mv minecraft-server-docker mcsrv
  3. Edit Dockerfile (if needed)

    • Open the Dockerfile and locate the line that installs Java:
      RUN apt-get update && \
          apt-get install -y curl openjdk-21-jdk wget
    • If you are running an older version of Minecraft, change the Java version to openjdk-8-jdk. Additionally, if your server requires extra packages (such as unzip) add them to this line. For example:
      RUN apt-get update && \
          apt-get install -y curl openjdk-8-jdk wget unzip
      Some servers might work with only openjdk-X-jre-headless installed, but you’ll need to experiment to find what works best.
  4. Build Container and Create Symlink

    • From inside the mcsrv directory, create a symlink to the Docker volume for easy access to your data:
      docker compose up && docker compose down
      ln -s /var/lib/docker/volumes/mcsrv_data/_data data
    • Note: The path to the volume may vary. You can check the exact path using docker volume inspect mcsrv_data
  5. Download Server Files

    • Download the Minecraft server files or modpack server files.
    • Place the .jar file or unzipped files into the data folder.
  6. Run Docker Container

    docker compose up -d

    Note: You must run this command inside mcsrv folder

  7. Attach to the Container

    docker attach mcsrv-mc-1

    You are now in the Docker container.

  8. Initial Server Configuration

    • Follow the server or modpack guide for the initial setup. If no guide is available, common steps include:
      • Run java -jar server.jar.
      • Accept the EULA by editing eula.txt.
        echo eula=true > eula.txt
      • Create a run.sh script with:
        java -Xmx8G -jar server.jar nogui
        Note: Adjust -Xmx8G to match the amount of RAM your server will use (in this case, 8GB).
    • Run the server manually for the first time, wait until the world generates, and stop it with stop.
  9. Detach and Stop the Container

    • Use Ctrl + P, then Ctrl + Q to detach from the container.
    • Run this command inside mcsrv folder to stop the container:
      docker compose down
  10. Finalize Docker Configuration

    • Edit the Dockerfile to uncomment the CMD line and ensure it points to your run.sh script.
    • If necessary, modify the line to match the script provided by the modpack. (e.g, startserver.sh, start.sh, etc.)

Usage

  • Start Server

    docker compose up -d

    Note: If you are running this command for the first time after installation, use docker compose up -d --build. Also, ensure you are executing the command inside the mcsrv folder.

  • Stop Server

    docker attach mcsrv-mc-1
    stop
  • Stop Server (Emergency)

    docker compose down

    Note: Use this command inside mcsrv folder if the server is unresponsive or crashes.

  • Access Server Console

    docker attach mcsrv-mc-1
  • Exit Console

    • Use Ctrl + P, then Ctrl + Q.

Uninstallation

  1. Remove Folder

    rm -rf mcsrv
  2. Remove Docker Container, Image, and Volume

    docker container rm -f mcsrv-mc-1
    docker image rm mcsrv-mc
    docker volume rm mcsrv_data

Troubleshooting

For issues or questions, refer to:

Contributors

Additional Information

Version: 1.0.19
Date: 2024-09-18
License: MIT License
Author: Filip Rokita

About

Easily deploy and manage Minecraft servers with this Docker setup. This project streamlines the process of running Minecraft servers, including various modpacks, by leveraging Docker's benefits of isolation, portability, and consistency. Simplify your server management and ensure a consistent environment across different machines.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published