Minecraft Server in Docker
This page documents how I configured my very first cloud server instance in the Developer Akademie DevSecOps Course.
TOC
Table of Contents
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:
Dockerfilefor building the Minecraft server imagedocker-compose.ymlfor container orchestration.envfile for environment variable configurationserver.propertiesfor 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
| Variable | Description | Default |
|---|---|---|
| SERVER_PORT | Port the server listens on | 8888 |
| ONLINE_MODE | Enforces Mojang account authentication | true |
| MAX_PLAYERS | Maximum number of players | 20 |
| DIFFICULTY | Game difficulty (peaceful, easy, normal, hard) | normal |
| GAMEMODE | Game mode (survival, creative, etc.) | survival |
| MOTD | Message of the day | My Production MC Server |
| ENABLE_COMMAND_BLOCK | Enable command blocks | false |
| PVP | Enable PvP | true |
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.