Draft: Creating portable docker containers.

I now have a setup with Docker containers that works for me after a few months of messing around with my new home server.  My containers are based on Docker-Compose and store the config and data of said containers in the same directory as the docker-compose.yml file is.

I like to run all my docker containers this way so that the install is very portable. I can backup the whole folder and copy it to a different server. Start up the docker container again and I’m back up and running

Overview

My setup has 3 important parts:

  1. Docker-compose built docker container
  2. Apache as reverse proxy
  3. Lets Encrypt for certificates

I usually grab an image from a public repository linuxserver.io has a big list of well working. My latest addition is NextCloud, an awesome file server cloud sharing thingie.

 

Prerequisites

docker-compose.yml

  1. create a directory for your container data
  2. docker-compose.yml
  3. pull images and start up container

create a docker compose file

start the docker container

I usually start it in screen so I can push it to the background.

A few interesting things in this docker-compose.yml

The volumes are relative to the docker compose file, for this docker compose file it means that a config and data container will be created. With you guessed it, your config and your data.

This way you can stop the docker container and back up the docker-compose.yml, config and data. This makes the whole setup portable.

There is some port mapping, port 443 of the container is mapped to 8000 to the host (see things to change)

Image – as said I like to use the linuxserver.io images.

Next steps

Create apache2 virtual host files, I usually start with this:

This won’t work at this moment but it is enough for LetsEncrypt auto to generate a certificate and create a virtual host

— run letsencrypt auto – select the secure option that also modifies the above file  the below file will be generated

Marked lines I’ve added myself.

— Set up is complete no

 

Things to change

  • Don’t use exposed hosts, but use docker hostnames or fixed IP’s or something, limiting ports that are exposed on the host.
  • Clean up article, its rough
  • add more info about enabled apache mods