26

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?

10 Answers 10

53

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

Sign up to request clarification or add additional context in comments.

3 Comments

this ans should be the upvoted, simple and working perfectly.
Second time this is saving my life ❤️
Applied your solution, but the issue persists.
40

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.

4 Comments

thank you sooo much it worked for me and my error was: [ERROR] [MY-010259] [Server] Another process with pid 60 is using unix socket file. [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file. [ERROR] [MY-010119] [Server] Aborting
Thanks a lot, worked for me as well. Same error but just another pid and running Docker Desktop on Mac OS M2
Did you mean the 'Files' tab? I cannot see the contents of the 'Files' tab due to the infinite 'Refreshing container files...' spinner message...
This should be selected answer, seems like container has culprit lock file...
21

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.

1 Comment

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”
8

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.

Comments

6

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.

1 Comment

For me the "my.cnf" file was at /etc/my.cnf, but this worked perfectly
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.

3 Comments

This actually worked for me. I had to be quick before the container shut down. But after a couple tries it worked :laughing: Nice one!
@danielito - Glad to hear I am not the only one :).
This worked like a charm. Extremely underrated answer!
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.

Comments

1

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.

Comments

1

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 ;)

2 Comments

This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From Review
How do you remove the cache?
0

I solved this by changing the image I was pulling from docker-compose.yml

There are also other ways to resolve this, such as deleting mysql.sock

You can follow this commands to verify if the files exist:

sudo ls /var/lib/docker/volumes/web_sail-mysql/_data

Case yes:

sudo rm /var/lib/docker/volumes/web_sail-mysql/_data/mysql.sock
sudo rm /var/lib/docker/volumes/web_sail-mysql/_data/mysql.sock.lock

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.