Przejdź do głównej zawartości

Minecraft Server in Docker

This page documents how I configured my very first cloud server instance in the Developer Akademie DevSecOps Course.

TOC

team-collaboration/version-control/githubGithub Tip

Table of Contents

  1. Description
  2. Quickstart
  3. Usage
  4. Configuration
  5. Persistence
  6. Testing
  7. Security Notes
  8. License

Description

This repository provides a ready-to-use production-grade Minecraft Java Edition server running inside a Docker container.
It uses docker-compose to simplify setup and supports persistent data storage so that your game world and configurations are preserved across restarts.

Main contents:

  • Dockerfile for building the Minecraft server image
  • docker-compose.yml for container orchestration
  • .env file for environment variable configuration
  • server.properties for Minecraft server settings

Quickstart

Prerequisites

  • Docker installed
  • Docker Compose installed
  • Java Edition Minecraft client for testing (optional)

Set up environment variables

cp .env.example .env

Edit .env with your desired settings before starting the server.

Start the server

git clone git@github.com:Gosia2024/minecraft_server.git
cd minecraft_server
docker compose up -d

The server will be available on port 8888 of your host/VPS IP.

Usage

Environment variables

Configure your environment variables by copying .env.example to .env and modifying as needed.

To apply changes after editing .env:

docker compose down
docker compose up -d

Editing server.properties

You can directly modify server.properties outside the container by editing it in the mounted volume and restarting the container.

Configuration

VariableDescriptionDefault
SERVER_PORTPort the server listens on8888
ONLINE_MODEEnforces Mojang account authenticationtrue
MAX_PLAYERSMaximum number of players20
DIFFICULTYGame difficulty (peaceful, easy, normal, hard)normal
GAMEMODEGame mode (survival, creative, etc.)survival
MOTDMessage of the dayMy Production MC Server
ENABLE_COMMAND_BLOCKEnable command blocksfalse
PVPEnable PvPtrue

Persistence

Game world data and configuration are stored in a Docker volume.
This ensures:

  • Worlds are not lost after server/container restarts.
  • Configuration changes persist across deployments.

Example volume mapping (from docker-compose.yml):

volumes:
- mc_data:/app/world

Testing

Option 1: Using mcstatus

Install mcstatus:

pip install mcstatus

Test connection:

python -m mcstatus <VPS-IP>:8888 status

Option 2: Using Minecraft Java Client

  • Launch Minecraft Java Edition.
  • Select Multiplayer.
  • Add a server with the address:
<VPS-IP>:8888
  • Join and start playing.

Security Notes

  • Do not store passwords, tokens, or private keys in the repository.

  • Use .env files for sensitive configurations and exclude them from Git (.gitignore).

  • Do not commit your VPS IP address to the repository.

  • Environment variables follow the convention: UPPER_CASE_WITH_UNDERSCORE.

  • Always reference variables in scripts with ${VAR_NAME} syntax.

License

This project is for educational purposes. Check Minecraft's EULA before running the server publicly.