I want to mount a directory from host inside mysql container so that mysql would write its logs to that directory and I would be able to access those logs from host.
For this I am using the following volume configuration:
volumes:
  - ./logs/mysql:/var/log/mysql
But as pointed out in this answer, there are permission issues between host user and container user. The solution there was to use named volumes, but what I want is to access those logs on host in a convenient directory. Not inside internal directories of docker.
So I ran the default image and made few observations
/var/log/mysql. This is because the default my.cnf has the error-log settings commented/etc/mysql/mysql.conf.d
/entrypoint.sh does change the permissions on /var/lib/mysql but not on /var/log/mysql
So to fix the issue you add a test.cnf file with below content
[mysqld]
log-error   = /var/log/mysql/error.log
general_log  = /var/log/mysql/log_output.log
And update your docker-compose with below settings
version: '2'
services:
  mysql:
    image: mysql:latest
    volumes:
      - ./logs:/var/log/mysql
      - ./test.cnf:/etc/mysql/mysql.conf.d/test.cnf
    environment:
      MYSQL_ROOT_PASSWORD: root
    entrypoint: ""
    command: bash -c "chown -R mysql:mysql /var/log/mysql && exec /entrypoint.sh mysqld"
This would make sure that before running the entrypoint script the proper permissions are set
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With