Skip to content
Jakob Runge edited this page Dec 24, 2015 · 5 revisions

The mariadb container

mariadb/build.sh builds the lingdb/mariadb container, which is essentially the same as the mariadb:latest container with a bit of labels. mariadb/run.sh starts an instance of the container passing it the password defined in the secrets directory. If the container runs it will have a name in the form of lingdb_mariadb_$(date -I)_$(pwgen 5 1). This makes sure that for every instance of the container we will know the date it was started and that containers from the same date have different names. If an exited container with a name that has lingdb_mariadb as a prefix is found, the volumes of that container will be reused, so that the database turns out to be the same after a possible update or restart of the container.

The mariadb/create container

build.sh

By executing mariadb/create/build.sh, the lingdb/mariadb_create image is created. The image is build from ubuntu:14.04.3 and installs mysql-client as well as the mariadb/create/create.sh, that is used as the entrypoint.

run.sh

The container can be started by mariadb/create/run.sh. The lingdb/mariadb_create container will be linked to a running lingdb_mariadb container, and will start inserting mariadb/create/create.sql into the database to perform initial table setup. If a mariadb/create/dump.sql is found, the container will execute that file against the database after create.sql thus making it possible to insert a dump.

The mariadb/backup container

build.sh

mariadb/backup/build.sh creates the lingdb/mariadb_backup container from ubuntu:14.04.3, adding mysql-client and mariadb/backup/dumpdb.sh. The container expects to be linked against a running lingdb_mariadb container, and the dumpdb.sh script will create periodic backups of the lingdb_mariadb database. These dumps will be named in ISO 8601 format, and thus have names like 2015-11-12.sql. The backup script runs a loop that performs these steps:

  • Create dump with current date
  • Delete all dumps except the last 10
  • Sleep 4 hours

run.sh

mariadb/backup/run.sh starts the lingdb/mariadb_backup container linking it against a running lingdb_mariadb container.

Accessing the database

To access the mariadb database from outside the container, the following steps are necessary:

  1. Use $ docker ps to obtain a list of all running containers, and find the lingdb/mariadb container that you want to connect to. This container will have a name like lingdb_mariadb_2015-12-24_xa5Ph.

  2. Use $ docker exec -it lingdb_mariadb_2015-12-24_xa5Ph ip a to execute ip a inside the choosen container and obtain its IP address.

  3. Have a look at /srv/container/secrets/secrets to obtain the root password.

  4. Use the root password, the root user and port 3306 to connect to the mariadb container, but note that the docker network that the container lives in is only accessible local to the server, so you'll likely need to tunnel there.

Clone this wiki locally