0

I am struggling with the proper use of docker-compose (for a local dev environment), when I include a data volume to a host directory mariadb (and mysql) fails. How do I use a host folder with docker-compose and with the correct permissions. I see several other data volume questions, but in this case the host folder is mounted and mariadb is not able to use it.

In my docker-compose.yml I have:

expressionengine:
  image: mariadb
  expose: 
   - "3306"
  volumes: # /var/lib/mysql is the datadir from my.cnf
   - ../containers/expressionengine/var-lib-mysql/:/var/lib/mysql
  environment:
   - MYSQL_ROOT_PASSWORD=password
   - MYSQL_DATABASE=expressionengine

But something is off:

Attaching to builddev_expressionengine_1
expressionengine_1 | Running mysql_install_db ...
expressionengine_1 | Installing MariaDB/MySQL system tables in '/var/lib/mysql/' ...
expressionengine_1 | 150603  5:15:20 [Note] /usr/sbin/mysqld (mysqld 10.0.19-MariaDB-1~wheezy-log) starting as process 38 ...
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: Using mutexes to ref count buffer pool pages
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: The InnoDB memory heap is disabled
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: Memory barrier is not used
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: Compressed tables use zlib 1.2.7
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: Using Linux native AIO
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: Not using CPU crc32 instructions
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: Initializing buffer pool, size = 256.0M
expressionengine_1 | 150603  5:15:20 [Note] InnoDB: Completed initialization of buffer pool
expressionengine_1 | 2015-06-03 05:15:20 7f2425ed9760  InnoDB: Operating system error number 13 in a file operation.
expressionengine_1 | InnoDB: The error means mysqld does not have the access rights to
expressionengine_1 | InnoDB: the directory.

Im not sure its permissions given that the mysql dir is written in the host holder. Im also on a mac with kitematic:

bash-3.2$ cd containers/expressionengine/var-lib-mysql/
bash-3.2$ ls -la
total 0
drwxr-xr-x  3 tom  staff  102 Jun  3 10:16 .
drwxr-xr-x  3 tom  staff  102 Jun  3 10:16 ..
drwxr-xr-x  2 tom  staff   68 Jun  3 10:16 mysql
Tom
  • 981
  • 11
  • 24
  • Definitely sounds like either permissions or SELinux. It would help if you added what `ls -l` on the directory shows, and `ls -lZ` if using SELinux. – Adrian Mouat Jun 03 '15 at 15:38
  • @AdrianMouat I updated the question. So docker-compose creates the files with host user credentials - can I chown in docker-compose after the dir is created? – Tom Jun 03 '15 at 16:26
  • I doubt docker-compose created any files. – Adrian Mouat Jun 03 '15 at 17:00

2 Answers2

1

The permissions are wrong.

To fix it, just run something like:

docker -v $(pwd)/containers/expressionengine/var-lib-mysql/:/var/lib/mysql mariadb chown -R mysql /var/lib/mysql

Assuming mysql is the correct user and you are currently in the directory below the containers folder.

In the future, you might find it easier to use a data container.

Adrian Mouat
  • 44,585
  • 16
  • 110
  • 102
  • I (think) i understand the value of data containers but for our dev environments I think it would be more productive to have the db storage on the host - just as our web server htdocs are. The question did not specify docker-compose, but I think its fair to expect a solution that will work with docker-compose since it was included. – Tom Jun 03 '15 at 17:23
  • A data container will store the data on the host (not in the UFS), but normally in a directory managed by Docker. You can use data containers with compose, but I wouldn't use compose to set up the data container. – Adrian Mouat Jun 03 '15 at 19:04
  • OK, so if i can not use compose, i have to make a dockerfile to set the directory ownership? and I can keep the data volume mapping in compose? – Tom Jun 03 '15 at 19:47
  • Assuming the mariadb image is set up correctly, you just need to do `docker run --name mariadb-dc mariadb echo "Maria DB Data Container"` then in your compose yml add a `volumes-from: mariadb-dc`. The image will take care of setting up the volume and ownership correctly. – Adrian Mouat Jun 03 '15 at 20:26
  • thanks a bunch for your comments. this sounds like a gross limitation of compose if once has to run containers prior to compose - or do I misunderstand compose? – Tom Jun 03 '15 at 20:44
  • Compose is for running containers. You don't run data containers, they're really just namespaces for volumes. – Adrian Mouat Jun 03 '15 at 20:53
0

The problem only exists on OSX and is related to how boot2docker uses vboxsf. The vboxsf is mounted with one UID, but the database service needs another. Related thread: https://github.com/kitematic/kitematic/issues/593

Tom
  • 981
  • 11
  • 24