Here I created docker container which use the mariadb image and created three volumes as below.


version: '2.0'

  image: mariadb:latest
  restart: always
  container_name: mariadb
    - MYSQL_DATABASE=testdb
   - 3307:3306
   - ./database:/var/lib/mysql
   - ./_conf/mariadb.cnf:/etc/mysql/my.cnf:ro
   - ./logs:/var/log/mysql

First two volume works successfully but I can't able to find mariadb-logs files into logs folder. I seems logs folder showing blank on host as well as on container(/var/log/mysql). I think host folder override into docker file system.

If I remove this volume(./logs:/var/log/mysql) from docker-compose then logs files are showing on container.

My plan is to mount /var/log/mysql/ folder to local machine.

Thanks !

  • Try chmod 777 /var/log/mysql on your host, I bet your daemon running as mysql user has no rights to write in this directory on your host. After that you'll have to find the mysql user id inside the container to make a chown to avoid lettign everyone read an write your db logs.
    – Tensibai
    Commented Sep 8, 2017 at 10:17
  • Perhaps selinux or apparmor is activated
    – 030
    Commented Sep 8, 2017 at 10:21
  • I'm using Debian os and apparmor already deactivate. Commented Sep 18, 2017 at 5:04

3 Answers 3


If you use CentOS 7 (as I have ). You may have SELinux turned on by default.check https://www.rootusers.com/how-to-enable-or-disable-selinux-in-centos-rhel-7/ or mount like this:

   - ./database:/var/lib/mysql:Z
   - ./_conf/mariadb.cnf:/etc/mysql/my.cnf:Z
   - ./logs:/var/log/mysql:Z

If you're running a RedHat-based distribution e.g. Fedora or CentOS, you may have SELinux turned on by default. You can automatically permit your containers to access files on the hosts by mounting with the :Z option, like so:

   - ./database:/var/lib/mysql:Z
   - ./_conf/mariadb.cnf:/etc/mysql/my.cnf:Z
   - ./logs:/var/log/mysql:Z

If /var/log/mysql:/var/log/mysql is defined as a volume then the content that reside in the container's /var/log/mysql/ will be stored in the /var/log/mysql/ folder on the host.

It could be possible that it is not possible to mount the /var/lib/mysql as SElinux or app armor is preventing this.


Note that users on host systems with SELinux enabled may see issues with this. The current workaround is to assign the relevant SELinux policy type to the new data directory so that the container will be allowed to access it:

$ chcon -Rt svirt_sandbox_file_t /my/own/datadir
  • yes I agree, ./database volume working fine and even I create file on ./logs folder on host then it will show on container but volume not working in revers order. Commented Sep 8, 2017 at 6:53
  • If for example the mysql container from dockerhub is run and the database is stored in /var/lib/mysql, the container is rebooted then the database that reside on the host will be found in the container as well
    – 030
    Commented Sep 8, 2017 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.