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

 

Advertisements

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