Skip to content

Instantly share code, notes, and snippets.

@lbrito1
Last active February 7, 2018 17:22
Show Gist options
  • Save lbrito1/22c6073811a334b938cee14d201cf248 to your computer and use it in GitHub Desktop.
Save lbrito1/22c6073811a334b938cee14d201cf248 to your computer and use it in GitHub Desktop.
Solving mysql socket problem on docker

Probem

mysql container starts failing with Could not create unix socket lock file /var/run/mysqld/mysqld.sock.lock., even though you created the correct volume that is used by mysqld and it has the correct permissions (777). The problem persists even if you remove the pid files from mysqld dir or it is empty already.

Why does this happen?

Hell if I know. My guess is: "Enable external locking (system locking), which is disabled by default. If you use this option on a system on which lockd does not fully work (such as Linux), it is easy for mysqld to deadlock."

https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_external-locking

Solution

  1. Copy the mysql container id:
$ docker ps -a | grep mysql
4f5b9dfabae9
  1. Create something which we can identify the container with within aufs: docker container start 4f5b9dfabae9 && docker exec -it 4f5b9dfabae9 touch abcdef

  2. Find the mnt folder for that container:

./aufs/diff/b3eae04cf6d5ec394f233e917568b64dafc42fa5a0be7591174164f0e42edd3e/abcdef
./aufs/mnt/b3eae04cf6d5ec394f233e917568b64dafc42fa5a0be7591174164f0e42edd3e/abcdef
  1. Using the path you found, edit my.cnf and add skip-external-locking to the last line: vim ./aufs/mnt/b3eae04cf6d5ec394f233e917568b64dafc42fa5a0be7591174164f0e42edd3e/etc/mysql/mysql.cnf

  2. ?????????????????

  3. Profit!

References

https://www.linuxquestions.org/questions/linux-newbie-8/mysqsl-installation-problem-4175589112/page3.html

TLDR add skip-external-locking to my.cnf:

e.g. /var/lib/docker/aufs/mnt/b3eae04cf6d5ec394f233e917568b64dafc42fa5a0be7591174164f0e42edd3e/etc/mysql/my.cnf

Long(er) term solution: rebuild image so that mysqld starts with skip-external-locking https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_external-locking

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment