NekoTone / alpine-mysql

Small MySQL/MariaDB Image on Alpine Linux + S6.

Home Page:https://woahbase.online/#/images/alpine-mysql

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build status commit version:x86_64 size:x86_64 version:armhf size:armhf version:armv7l size:armv7l version:aarch64 size:aarch64

Container for Alpine Linux + S6 + MySQL/MariaDB


This image serves as the base image for applications / services that need a MySQL database running.

If it is required to run in the same container as the app is running, use this container as the source for your app. Can setup i.e create the databse user and the database specified in the command line if not already exists.

Has handy backup and restore commands available inside the image.

Based on Alpine Linux from my alpine-s6 image with the s6 init system overlayed in it.

The image is tagged respectively for the following architectures,

  • armhf
  • armv7l
  • aarch64
  • x86_64 (retagged as the latest )

non-x86_64 builds have embedded binfmt_misc support and contain the qemu-user-static binary that allows for running it also inside an x86_64 environment that has it.


Get the Image


Pull the image for your architecture it's already available from Docker Hub.

# make pull
docker pull woahbase/alpine-mysql:x86_64

Run


If you want to run images for other architectures, you will need to have binfmt support configured for your machine. multiarch, has made it easy for us containing that into a docker container.

# make regbinfmt
docker run --rm --privileged multiarch/qemu-user-static:register --reset

Without the above, you can still run the image that is made for your architecture, e.g for an x86_64 machine..

This image already has a user mysql configured to drop privileges to the passed PUID/PGID which is ideal if its used to run in non-root mode. That way you only need to specify the values at runtime and pass the -u mysql if need be. (run id in your terminal to see your own PUID/PGID values.)

Configurations are located at /etc/mysql and the data at /var/lib/mysql. The default my.cnf is provided, replace the file or rebind the whole directory with your configs. Otherwise the environment variables MYSQL_ROOT_PWD MYSQL_USER MYSQL_USER_PWD MYSQL_USER_DB are used to setup a non-root user and a database if not done already.

Running make starts the service.

# make
docker run --rm -it \
  --name docker_mysql --hostname mysql \
  -c 512 -m 512m \
  -e PGID=100 -e PUID=1000 \
  -e MYSQL_ROOT_PWD=insecurebydefault \
  -e MYSQL_USER=mysql \
  -e MYSQL_USER_PWD=insecurebydefault \
  -e MYSQL_USER_DB=test \
  -p 3306:3306 \
  -v data:/var/lib/mysql \
  -v /etc/hosts:/etc/hosts:ro \
  -v /etc/localtime:/etc/localtime:ro \
  woahbase/alpine-mysql:x86_64

Stop the container with a timeout, (defaults to 2 seconds)

# make stop
docker stop -t 2 docker_mysql

Removes the container, (always better to stop it first and -f only when needed most)

# make rm
docker rm -f docker_mysql

Restart the container with

# make restart
docker restart docker_mysql

Shell access


Get a shell inside a already running container,

# make debug
docker exec -it docker_mysql /bin/bash

set user or login as root,

# make rdebug
docker exec -u root -it docker_mysql /bin/bash

To check logs of a running container in real time

# make logs
docker logs -f docker_mysql

Backup database

# make backup DBNAME=<databasename>
# the backup will be named <databasename>.sql and is dropped
# inside /var/lib/mysql/backups (local path: data/backups)
docker exec -it docker_mysql /scripts/run.sh backup <databasename>

Restore a single database

# make restore DBNAME=<databasename>
# restores the <databasename> database from the file
# /var/lib/mysql/backups/<databasename>.sql
# (local path: data/backups/<databasename>.sql should exist)
docker exec -it docker_mysql /scripts/run.sh restore <databasename>

Development


If you have the repository access, you can clone and build the image yourself for your own system, and can push after.


Setup


Before you clone the repo, you must have Git, GNU make, and Docker setup on the machine.

git clone https://github.com/woahbase/alpine-mysql
cd alpine-mysql

You can always skip installing make but you will have to type the whole docker commands then instead of using the sweet make targets.


Build


You need to have binfmt_misc configured in your system to be able to build images for other architectures.

Otherwise to locally build the image for your system. [ARCH defaults to x86_64, need to be explicit when building for other architectures.]

# make ARCH=x86_64 build
# sets up binfmt if not x86_64
docker build --rm --compress --force-rm \
  --no-cache=true --pull \
  -f ./Dockerfile_x86_64 \
  --build-arg DOCKERSRC=woahbase/alpine-s6:x86_64 \
  --build-arg PGID=1000 \
  --build-arg PUID=1000 \
  -t woahbase/alpine-mysql:x86_64 \
  .

To check if its working..

# make ARCH=x86_64 test
docker run --rm -it \
  --name docker_mysql --hostname mysql \
  -e PGID=1000 -e PUID=1000 \
  woahbase/alpine-mysql:x86_64 \
  sh -ec 'mysql --version'

And finally, if you have push access,

# make ARCH=x86_64 push
docker push woahbase/alpine-mysql:x86_64

Maintenance


Sources at Github. Built at Travis-CI.org (armhf / x64 builds). Images at Docker hub. Metadata at Microbadger.

Maintained by WOAHBase.

About

Small MySQL/MariaDB Image on Alpine Linux + S6.

https://woahbase.online/#/images/alpine-mysql


Languages

Language:Makefile 51.8%Language:Shell 48.2%