2

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?

Jonas
  • 97,987
  • 90
  • 271
  • 355
config.err
  • 41
  • 6

2 Answers2

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

danblack
  • 7,260
  • 2
  • 13
  • 31
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 :( :)

config.err
  • 41
  • 6