Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda