Skip to content

Dockerfile & build steps for running a pmmp server.

Notifications You must be signed in to change notification settings

NxtLvLSoftware/docker-pmmp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-pmmp

Hosts the files used to build nxtlvlsoftware/pmmp & nxtlvlsoftware/pmmp-phpstan docker images.

About

This repository contains the source for building a minimal docker image for running a pocketmine server and an image for running static analysis on plugin source code using phpstan.

If you're interested in building your own images, want to understand how everything works or just feel like reading something, you can take a look at the documentation for the pocketmine image here and the phpstan image here.

Index

What the heck is docker?

Docker lets you install software more easily by "copying the whole machine over". To use Docker, you must be on a Linux/MacOS machine. (Docker also works on Windows, but trying to run Linux containers on Windows usually creates more problems than it solves.)

To install Docker, refer to the official Docker docs.

Running PocketMine

There are pre-built images avalible on dockerhub that you can install with the steps below or you may build your own images from a specific git tag by following the directions here.

Quick start

You do NOT need to clone this repo to install pocketmine via docker!

Although this is a quick start guide, you will still need to know how to run commands on a Linux/MacOS machine and already have Docker installed.

(If you prefer a more technical reference, there is in-depth documentation available with the full build instructions.)

Required volumes

The pocketmine image uses two volumes for storing your servers data, /data (where things like server.properties, plugin data, player data, etc. is stored) and /plugins where your .phar files are stored.

Mounting the volumes

If you want to use existing directories or don't want the server data or plugins stored in the container you can mount the directories from your host machine. First, make sure the directories data and/or plugins exist (you can create them in your current working directory with mkdir data plugins & they can have any name you like).

Setting file permissions

Set the owner of these directories to user of UID 1000. Docker containers identify file owners using the UID, so if your current user is coincidentally also UID 1000 (you can check this with echo $UID), this operation might do nothing. Otherwise, you might need root access to change the owner of a directory:

sudo chown -R 1000:1000 data plugins

Starting the server

You can now start the server with the following command:

docker run -it -v $PWD/data:/data -v $PWD/plugins:/plugins nxtlvlsoftware/pmmp:stable

If your directories aren't named data or plugins you can replace $PWD/data and/or $PWD/plugins with the full/absolute path to your directories:

docker run -it -v /home/user/server-1/data:/data -v /home/user/server-1/plugins:/plugins nxtlvlsoftware/pmmp:stable

Changing the port

Do NOT change the server port in server.properties. If you want to open the server on another port (e.g. 12345 instead), start the server with the following command:

docker run -it -p 12345:19132 -v $PWD/data:/data -v $PWD/plugins:/plugins nxtlvlsoftware/pmmp:stable

(The second number is ALWAYS 19132)

Run the server in the background

To run the server in the background, simply change -it to -itd in the commands above. This will run the server in the background even if you close the console. (No need to screen/tmux anymore!)

When you run this command, it will display the container name that runs the server, e.g. admiring_boyd, bold_kilby, or other random names.

Reattaching to a server in the background

To open the console of a background server (reattach), run the following command:

docker attach container_name

To leave the console again, just press Ctrl p Ctrl q.

Viewing background server logs

Alternatively, you can use docker logs container_name to view the console output without getting stuck in the console.

Running phpstan (code analysis)

You can also choose to use a pre-built image from dockerhub for running phpstan but if you are targetting a specific tag or fork of pocketmine you will need to build your own image following the provided instructions.

Quick start (phpstan)

You do NOT need to clone this repo to install the pocketmine phpstan code analysis image!

Although this is a quick start guide, you still need to know how to run commands on a Linux/MacOS machine and already have Docker installed.

(If you prefer a more technical reference, there is in-depth documentation section available with the full build instructions.)

Required volume

The phpstan image uses a single volume for running analysis on your code, this is usually the directory where your src folder and plugin.yml file are located. Make sure to create the directory or have your plugins source directory available (easiest if you cd to it/its your current working directory).

Running the analysis

Now you can run phpstan analysis with the following command:

docker run -it -v $PWD:/source nxtlvlsoftware/pmmp-phpstan:stable

This will run php stan with the default configuration provided with image on the plugin in your current working directory. If your plugin source is in another directory you can replace $PWD with the full/absolute path to your plugins source folder:

docker run -it -v /home/dev/my-plugin:/source nxtlvlsoftware/pmmp-phpstan:stable

Resolving plugin dependencies

If your plugin lists dependencies in its plugin.yml (depend, softdepend or loadbefore) the container will try and find the latest versions of each plugin listed on poggit and download them into /deps if found. The default phpstan configuration will automatically autoload all files under /deps so the analysis is aware of your plugins dependencies.

Resolving composer dependencies

If a composer.json file is present in your plugins root directory (along side plugin.yml) the container will attempt to install the dependencies. The default phpstan configuration does not include the autoloader generated by the composer install command so you will need to provide your own config.

Custom phpstan configuration

If the default phpstan configuration is not sufficient you can specify the path to your own phpstan.neon file as an environment variable if it exists in your plugins source folder:

docker run -it -v $PWD:/source -e PHPSTAN_CONFIG=/source/phpstan.neon.dist nxtlvlsoftware/pmmp-phpstan:stable

Given your plugins directory structure looks something like the following:

my-plugin
  > src
  > plugin.yml
  > phpstan.neon.dist

This will tell php stan to look for the phpstan.neon.dist file provided by your source directory (this should be the root directory that includes /src, /plugin.yml, etc). In the container your plugins root directory will be mounted under /source so you need to provide the path to your configuration file relative to the path you mount to /source.

Autoloading pocketmine

If you provide your own phpstan configuration you will need to tell phpstan to autoload the pocketmine classes or the analysis will fail. The easiest way to achieve this is by telling phpstan about the composer generated autoloader in the phar:

autoload_files:
	- phar:///pocketmine/PocketMine-MP.phar/vendor/autoload.php

Default configuration

If you run into issues configuring phpstan you may find it helpful to take a look at the default configuration provided.

About

Dockerfile & build steps for running a pmmp server.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published