10

I'm trying to run a docker mysql container with initialized db according instruction provided in this message https://stackoverflow.com/a/29150538/6086816. After first run it works ok, but on second run, after trying of executing /usr/sbin/mysqld from script, I get this error:

db_1 | 2016-03-19T14:50:14.819377Z 0 [ERROR] Another process with pid 10 is using unix socket file.

db_1 | 2016-03-19T14:50:14.819498Z 0 [ERROR] Unable to setup unix socket lock file.

...

mdir_db_1 exited with code 1

what can be the reason of it?

Community
  • 1
  • 1
Arnold Eden
  • 99
  • 1
  • 1
  • 6

9 Answers9

12

I was facing the same issue. Following are the steps that I tried to resolve this issue -

  • Firsly, stop your docker service by using following command - "sudo service docker stop"

  • Now,get into the docker folder in my Linux system using the following path - /var/lib/docker.

  • Then within the docker folder you need to get into the volumes folder. This folder contains the volumes of all your containers (memory of each container) - cd /volumes

  • After getting into volumes do 'sudo ls' you will find multiple folders with hash names. These folders are volumes of your containers. Each folder is named after its hash (You need to inspect your docker container and get the hash of your container volume. For this, you need to do the following steps -

Run command "docker inspect 'your container ID' ".

Now you will get a JSON file. It is the config file of your docker container.

Seach for Mounts key within this JSON file. In Mounts, you will get the Name(hash) of your volume. (You will also get the path of your volume within the Mounts. Within Mounts "Name" key is your volume name and "Source" is the path where your volume is located.)).

  • Once you get the name of your volume you can go within your volume folder and within this folder you will find "_data" folder. Get into this folder.

  • Finally within "_data" folder use sudo ls command and you will find a folder with the name mysql.sock.lock. Remove this folder By "rm -f mysql.sock.lock".

  • Now restart your docker service and then start your docker container. It will start working.

Note- Use sudo in each command while you are in the docker container folder.

shubham tak
  • 121
  • 1
  • 5
  • 2
    Quick note: if folder /var/lib/docker doesn't exist, and you use docker desktop. You can access data folder of volumes in docker desktop menu. Volumes → click `volume name`→ select `data` tab. And here remove “mysql.sock.lock” – halcyon Jun 20 '23 at 16:42
6

I solved this issue by doing the following command:

docker-compose down --volumes

And then:

sail up --build

https://rawbinn.com/blog/mysql-not-starting-on-docker

5

You should make sure the socket file have been deleted before you start mysql.Check my.cnf(/etc/mysql/my.cnf) file to get the path of socket file. find sth like this socket = /var/run/mysqld/mysqld.sock.And delete the .sock.lock file as well.

xingyu chen
  • 51
  • 1
  • 2
5

Just faced same problem.

After many research, summary of my solution:

  1. Find host location of docker files

    $ docker inspect <container_name> --> Mounts.Source section

Interesting part of docker inspect

In my case, it was /var/snap/docker/common/.../_data

As root, you can ls -l that directory and see the files that are preventing your container from starting, the socket mysql.sock and the file mysql.sock.lock

enter image description here

Simply delete them as root ($ sudo rm /var/snap/.../_data/mysql.sock*) and start your docker container.

NOTE: be sure you don't have any other mysql.sock... files than those two. In that case don't use wildcar (*), delete each of them individually.

Hope this helps.

Carlos
  • 105
  • 2
  • 6
2

I had the same problem and got rid of it in an easy and mysterious way.

First I have noticed that I am unable to start mysql_container container. Running docker logs mysql_container indicated exactly the same problem as described repeating for few times.

I wanted to get a look around by running the container in an interactive mode by docker start -i mysql_container from one bash window while running things like docker exec -it mysql_container cat /etc/mysql/my.cnf in another.

I have done that and was very surprised to see that this time the container started successfully. I cannot understand why. I can only guess that starting an interactive mode together with running subsequent docker exec commands slowed down init process and some another process had a bit more time to remove its locks.

Hope that helps anybody.

Kuba D
  • 93
  • 1
  • 7
1

This is a glitch with docker.

Execute following commands:

docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)

This will stop all containers and remove them.

After this it should work just fine.

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
1

Thanks to halcyon comment:

If you use docker desktop. In menu → "Volumes" → click your volume name → select "data" tab. And here remove “mysql.sock.lock” Now mysql works.

Ehsan Paknejad
  • 154
  • 1
  • 7
0

Generally this means a previously-running MySQL instance has placed a lock on the DB via the filesystem.

If you're sure no instances are running, you can delete the dangling locks that remain and no conflict error will appear.

As per shubham tak's answer you can remove these locks that are persisting on the Docker virtual filesystem by removing them from the host computer's filesystem directly.

Or, you can use the Docker CLI to blast it all away and start fresh:

docker system prune
docker volume prune

And then try again.

Bryce
  • 6,440
  • 8
  • 40
  • 64
0

I faced the same problem.

Docker caches it's images for faster container composing.

I found, by removing the cached image of 'mysql/mysql-server:8.0' and then trying 'sail up'/'compose up' again. Docker downloads a fresh images which solved the socket problem.

ERROR MESSAGE:
Another process with pid 62 is using unix socket file.
Unable to setup unix socket lock file.

Lesson learned: Don't doubt yourself and Try again from the start.

Keep Coding Beauties ;)

MVAHD
  • 1
  • 1
  • This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/34687372) – Yogendra Jul 19 '23 at 08:30