MariaDB mysqldump via older docker image

One of my mysqldump backup scripts was throwing error mysqldump: Couldn't execute 'select column_name, extra, generation_expression, data_type from information_schema.columns where table_schema=database() and table_name='wp_commentmeta'': Unknown column 'generation_expression' in 'field list' (1054)

Looks like it’s due version mismatch of my MariaDB mysqldump (on my system 10.11) and remote MariaDB version (is 10.1)

I ended up replacing it with the following docker command combo

#/bin/bash
DB_HOST="HOST"
DB_PORT=3306
DB_USER="USER"
DB_PASS="PASS"
DB_NAME="NAME"
BACKUP_DIR="$HOME/Dropbox/sql"
DB_FILE="dump.sql"
if which docker >/dev/null 2>&1 ; then
rm -f $BACKUP_DIR/$DB_FILE.gz
docker run -it –name backup-mariadb mariadb:10.1 mysqldump –compress –add-drop-table –skip-comments –events –routines \
-h $DB_HOST -P $DB_PORT -u $DB_USER -p$DB_PASS $DB_NAME -r $DB_FILE
docker cp backup-mariadb:dump.sql "$BACKUP_DIR/$DB_FILE"
docker rm backup-mariadb
gzip $BACKUP_DIR/$DB_FILE
rm -f $BACKUP_DIR/$DB_FILE
fi

Traefik test drive Docker container discovery

Simple config for testing Traefik with Docker:

# traefik.toml
debug = true

[api]
entryPoint = 'traefik'
debug = true

[docker]
endpoint = 'unix:///var/run/docker.sock'
domain = 'docker.localhost'
watch = true

Run Traefik in a docker container:

docker run --rm -l traefik -p 8080:8080 -p 80:80 \
    -v $PWD/traefik.toml:/etc/traefik/traefik.toml \
    -v /var/run/docker.sock:/var/run/docker.sock traefik

Fire up one docker compose setup and visit http://localhost:8080


docker run –rm -l traefik -p 8080:8080 -p 80:80 \
-v $PWD/traefik.toml:/etc/traefik/traefik.toml \
-v /var/run/docker.sock:/var/run/docker.sock traefik

view raw

run-traefik.sh

hosted with ❤ by GitHub


debug = true
[api]
entryPoint = 'traefik'
debug = true
[docker]
endpoint = 'unix:///var/run/docker.sock'
domain = 'docker.localhost'
watch = true

view raw

traefik.toml

hosted with ❤ by GitHub

Log mysql queries in Docker container

To log mariadb (mysql) SQL queries in a Docker container add - ./docker/mysql/conf.d:/etc/mysql/conf.d to volumes of the database service.

version: '3'

services:
   db:
     container_name: db
     image: mariadb:10.1
     volumes:
       - db_data:/var/lib/mysql
       - ./docker/mysql/conf.d:/etc/mysql/conf.d
     environment:
       MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'

volumes:
    db_data:

The contents of docker/mysql/conf.d/my.cnf

# docker/mysql/conf.d/my.cnf

[mysqld]
general_log = 1
general_log_file = /var/log/mysql/query.log

slow_query_log = 1
long_query_time = 1 # seconds
slow_query_log_file = /var/log/mysql/slow.log
log_queries_not_using_indexes = 0

 

Docker Cannot create container for service db: devmapper: Error mounting

Just wanted to start working and got the following error from Docker:

Cannot create container for service db: devmapper: Error mounting ...

Gladly I remembered that I updated the Linux kernel in the morning so after computer restart I had no issue 🙂

Thanks Arch Linux for the kick to learn Docker

Thanks to Arch Linux and its rolling release strategy it comes with PHP 7.1 as default. After some months of having the following in /etc/pacman.conf

IgnorePkg = php php-apache php-gd php-intl php-mcrypt php-pgsql php-geoip php-cgi php-embed php-enchant php-fpm php-imap php-odbc php-phpdbg php-pspell php-snmp php-sqlite php-tidy php-xsl

I pushed myself to learn more and finally start creating some Dockerfiles for some legacy PHP projects.

ss_2017-09-05-11-10-31
Docker host vs. local host PHP

Connect to localhost MySQL from Docker container

To test connection to MySQL/MariaDB server running on localhost from Docker container try:

docker run --rm -it --net=host mariadb mysql -u root -h 127.0.0.1
--rm  Automatically remove the container when it exits https://docs.docker.com/engine/reference/run/#clean-up-rm
-i    Keep STDIN open even if not attached https://docs.docker.com/engine/reference/run/#foreground
-t    Allocate a pseudo-TTY
--net Connect a container to a network https://docs.docker.com/engine/reference/run/#network-settings