Here’s another simple “Gotcha” to look out for. Let’s say you’ve started your local MySql docker container. Now you’re having trouble connecting to it, even though you know you’re forwarding the proper port to your Docker container and your mysql user is set up to accept connections from the host machine. Yet for some reason, you keep getting this error while attempting to log in:

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

Look familiar? You’ll notice it’s attempting to connect to MySql via a socket, when what you really want it to do is treat it like a normal remote host. This is where the --protocol flag comes in. Try this command, and likely you’ll be in like Flynn:

$ mysql -u <username> -p<password> -P <port number> --protocol TCP