sqitchers / docker-sqitch

Docker Image packaging for Sqitch
MIT License
35 stars 39 forks source link

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' #9

Closed franciscohanna92 closed 4 years ago

franciscohanna92 commented 5 years ago

This issue was originally solved here. I'm adding it here to keep track of it in this repo.

So, I was trying to use Sqitch from the docker image using the bash script provided there. My MySQL was running on my localhost. When I tried to use sqitch, it said:

Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

What I did to solve it was to locate the mysqld.sock in my localhost, and mounting the folder that contained (/run/mysqld) it in the container's /var/run/mysqld folder, adding the following parameter to docker run:

--mount "type=bind,src=/run/mysqld,dst=/var/run/mysqld"

The docker run command ended up as:

docker run -it --rm --net="host" \
    --mount "type=bind,src=/run/mysqld,dst=/var/run/mysqld" \
    --mount "type=bind,src=$(pwd),dst=/repo" \
    --mount "type=bind,src=$HOME,dst=$homedst" \
    "${passopt[@]}" "$SQITCH_IMAGE" "$@"
theory commented 5 years ago

Consider adding documentation to the README or the Docker Hub page listing ways to connect to database servers on the hosting machine from inside the container.

theory commented 4 years ago

See notes on #10 for the reason the notes in 66b22b3 are preferred.