Volatil3
Volatil3

Reputation: 14978

Docker on Mac: Unable to run MySQL

I am using Docker very first time. On running command: make kickoff I am getting error:

myapp_php_apache_engine_dev is up-to-date
Starting myapp_mysql_dev

ERROR: for mysql  Cannot start service mysql: invalid header field value "oci runtime error: container_linux.go:247: starting container process caused \"process_linux.go:359: container init caused \\\"rootfs_linux.go:53: mounting \\\\\\\"/Applications/MAMP/htdocs/clients/codingmachine/myapp/mysql/custom-my.cnf\\\\\\\" to rootfs \\\\\\\"/mnt/sda1/var/lib/docker/aufs/mnt/2ab6b2578ad9f8da2d453aefa5cd9b288fee30dd2d73efc3048627cf0861d55a\\\\\\\" at \\\\\\\"/mnt/sda1/var/lib/docker/aufs/mnt/2ab6b2578ad9f8da2d453aefa5cd9b288fee30dd2d73efc3048627cf0861d55a/etc/mysql/mysql.cnf\\\\\\\" caused \\\\\\\"not a directory\\\\\\\"\\\"\"\n"
ERROR: Encountered errors while bringing up the project.
make: *** [up] Error 1

Upvotes: 0

Views: 688

Answers (1)

thaJeztah
thaJeztah

Reputation: 28987

When running docker toolbox, the docker daemon runs in a VirtualBox VM. The daemon (and containers, which run inside that VM) therefore don't have access to files on your host (Mac OS X).

When you bind-mount a directory from your host into the container (so that the container can access those files), files are always mounted from the host that the daemon runs on; in your case, the VirtualBox VM.

Docker Toolbox uses a "trick" to allow you to mount files from your host; files inside the /Users/ directory are shared with the VirtualBox VM using VirtualBox "guest additions". This means that when you run;

docker run -v /Users/myname/somedir:/var/www/html -d nginx

The docker daemon mounts the /Users/myname/somedir directory from the VM into the container. Due to the guest additions "trick", this path actually is shared with your OS X machine, so the container "sees" the files from your OS X machine.

However, any directory outside of the /Users/ directory is not shared between the OS X machine and the VM. If you try to bind-mount a path that does not exist inside the VM, docker creates an empty directory (it assumes you want to mount a directory, because it has no way to tell if it should be a directory or a file), and mounts that directory inside the container.

In your example, you try to bind mount;

/Applications/MAMP/htdocs/clients/codingmachine/myapp/mysql/custom-my.cnf

Inside the container at;

/etc/mysql/mysql.cnf

The /Applications directory is not shared with the VM, so docker creates an empty directory named custom-my.cnf inside the VM, then tries to mount that directory at /etc/mysql/mysql.cnf inside the container. This fails, because you cannot mount a directory on top of a file, and Linux produces an error "not a directory".

To resolve your issue;

Upvotes: 1

Related Questions