Running Evennia in Docker

Dan Feeney edited this page Jan 24, 2017 · 1 revision
Clone this wiki locally

Evennia now has an official docker image which makes running an Evennia-based game in a Docker container easy.

This page describes how to get started.

Benefits

The primary benefit to running an Evennia-based game in a container is to simplify its deployment into a public production environment. Most cloud-based hosting providers these days support the ability to run container-based applications. This makes deploying or updating your game as simple as building a new container image locally, pushing it to your Docker Hub account, and then pulling from Docker Hub into your AWS/Azure/other docker-enabled hosting account. The container eliminates the need to install Python, set up a virtualenv, or run pip to install dependencies.

Setup

These steps assume that you have already installed Evennia locally and used evennia --init <gamedir> to create a game directory, or have otherwise cloned a working game directory from elsewhere.

  • Make sure you have installed Docker for your local O/S.
  • Create a new blank text file in the game directory named Dockerfile.
  • Put the following line into the new Dockerfile and save it.
FROM evennia/evennia:latest
  • In your login shell (or PowerShell on Windows), cd to your game directory.
  • Build your game container with the following command, assuming your Docker Hub account is "mydhacct" and you'd like to tag your game image as "mygame":
docker build -t mydhacct/mygame .
  • Once built, you have a couple of options to run your game. To run the container locally for development, we mount the local game directory as a volume inside the container as we start it with the command line:
docker run -it -p 8000-8001:8000-8001 -p 4000:4000 -v ${PWD}:/usr/src/game mydhacct/mygame
  • In a production environment, the container uses a bulit-in named volume, so we can omit the -v option:
docker run -it -p 8000-8001:8000-8001 -p 4000:4000 mydhacct/mygame

Once the game container is up and running, it should be accessible at the normal URL: http://localhost:8000/

How it Works

The evennia/evennia docker image holds the evennia library and all of its dependencies. It also has an ONBUILD directive which is triggered during builds of images derived from it. This ONBUILD directive handles setting up a volume and copying your game directory code into the proper location within the container.

In most cases, the Dockerfile for an Evennia-based game will only need the FROM evennia/evennia:latest directive, and optionally a MAINTAINER directive if you plan to publish your image on Docker Hub and would like to provide contact info.

For more information on Dockerfile directives, see the Dockerfile Reference.

For more information on volumes and Docker containers, see the Docker site's Manage data in containers page.

Additional Creature Comforts

The Docker ecosystem includes a tool called docker-compose, which can orchestrate complex multi-container applications, or in our case, store the default port and terminal parameters that we want specified every time we run our container. A sample docker-compose.yml file to run a containerized Evennia game in development might look like this:

version: '2'

services:
  evennia:
    image: mydhacct/mygame
    stdin_open: true
    tty: true
    ports:
      - "8000-8001:8000-8001"
      - "4000:4000"
    volumes: 
      - .:/usr/src/game

With this file in the game directory next to the Dockerfile, starting the container is as simple as

docker-compose up

For more information about docker-compose, see Getting Started with docker-compose.