Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

259
Views
Docker can't connect to local MySQL server through socket

I'm a newbie to docker and I'm facing a strange error.

When I run

docker run --name some-mysql-5 -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=secret mysql:latest

followed by

docker exec -ti containerid bash 
mysql -uroot -psecret

mysql works fine and I can create and populate databases.

But when I try to create a persistent host volume in order to create a shared db like this:

docker run --name some-mysql-4 -v C:\Users\User\Desktop\shared_vol_test:/var/lib/mysql/data -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=secret mysql:latest

followed by

docker exec -ti containerid bash 
mysql -uroot -psecret

I get the following error

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I've also tried to run it as an admin but the results are the same.

What am I doing wrong?

Am I creating a shared and persistent volume in the right way?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

/var/run/mysqld isn't a shared filesystem between containers. Use the tcp port 3306 for connecting between containers or share the /var/run/mysqld

over 4 years ago · Santiago Trujillo Report

0

I've found a workaround by creating the volume in this folder var/lib/mysql instead of var/lib/mysql/data

I've followed the first steps from this guide and it worked out for now.

I say for now because when I tried to execute mysql -uuser -ppass the first time didn't work out by dening me the access and after a while it worked with the same credentials and the same command so I could create a db. The db now is present on my host target directory so maybe I've found a solution to my problem. Here is mentioned something about the mysql time to be ready, there are still a lot of behaviours that I must understand I guess.

My account name says it all :( :)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!