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.
The contents of
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
I’m used to watch logs via multitail and as I migrated to using Docker for development I had to come up a command with which I can spectate container logs.
I ended up with the following
docker-compose logs --no-color -f | multitail -j
For reference docs.docker.com/compose/reference/logs/
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 to Arch Linux and its rolling release strategy it comes with PHP 7.1 as default. After some months of having the following in
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.
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