Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda