Photo Cred lifehacker

Choosing Your OS

For my OS, I'll be running Ubuntu 18.04, but this should be relatively universal on other operating systems.

Installing Docker

For steps on installing Docker on Ubuntu 18.04, please view my article:
http://www.philipgreco.com/installing-docker-on-ubuntu-18-04/

Finding a Minecraft Docker Image

For the Docker image I used itzg/minecraft-server as it appears to be the most popular on Docker Hub.

Creating a Data Directory

On your host server, create a directory to host the container's data. That way if the container ever gets deleted or something unexpected happens, the data will remain intact. For this instance I created:

/home/<user>/minecreft/demo_data

Running the Image

To pull the image from Docker Hub & run the container, execute the following command:

docker run -d -e EULA=TRUE -p 25565:25565 -v /home/<user>/minecreft/demo_data:/data --name mc itzg/minecraft-server

If Docker was able to find the image,you will see it start to pull the necessary files:

latest: Pulling from itzg/minecraft-server
e7c96db7181b: Pull complete 
f910a506b6cb: Pull complete 
b6abafe80f63: Pull complete 
dfaf32f74a69: Pull complete 
195f399818fa: Pull complete 
e2a91718b8c3: Pull complete 
2da0f3e7910a: Pull complete 
351dfad44054: Pull complete 
43cd429fbdf4: Pull complete 
2a26b7218bc1: Pull complete 
1c8246dcd403: Pull complete 
10cd1ff58e52: Pull complete 
b057292f6073: Pull complete 
484fc960c9ad: Pull complete 
92db2cd6d337: Pull complete 
be25f98f038c: Pull complete 
af59529c526d: Pull complete 
8000d576519d: Pull complete 
64225126d72a: Pull complete 

Breaking Down the Docker Run Command

Running the Docker container in the background (detatched):

-d

Set environment variables (Minecraft forces you to accept their EULA):

-e EULA=TRUE

Publish a container's port(s) to the host:

-p 25565:25565

Bind mount the Minecraft server's /data directory to the hosts volume:

-v /home/<user>/minecreft/demo_data:/data

Assign a name to the container:

--name mc

Checking the Container's Status

Since we ran the container detatched, we wont see anything in the standard output. To check the container's status run the following command:

docker container ls

You should see the following showing the status is "Up":

CONTAINER ID        IMAGE                          COMMAND             CREATED             STATUS                    PORTS                                 NAMES
35869476ab7f        itzg/minecraft-server:latest   "/start"            16 minutes ago      Up 16 minutes (healthy)   0.0.0.0:25565->25565/tcp, 25575/tcp   mc

Checking the Bind Mount

On the host machine, change directory (cd) to the data directory we created earlier. Run "ls" and you should see the Minecraft server's data:

banned-ips.json      config    logs                         mods      plugins            usercache.json  world
banned-players.json  eula.txt  minecraft_server.1.14.3.jar  ops.json  server.properties  whitelist.json

Checking Logs

If you ever need to check the container's logs, you can execute the following command which will follow the logs in realtime:

docker logs -f mc

Connect & Play

On your Minecraft client, direct connect to the IP address of your host server and have fun!

2019-07-14_13-35-1