mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
But after the script completes if I run the command in my terminal on the now running container it works just fine.
I also tried -h127.0.0.1 but that didn’t work either.
What is going on here. I don’t have any mysql related env vars in my shell so that can’t be it.
There’s a couple of ideas that I have that could be going wrong here.
1 - Do you have a global configuration for bash scripts that kills a bash script after a warning pops up ? If so the warning from mysql will have killed the script when you tried running your last docker exec statement.
2 - Could you adjust the bash script to print out the value of MYSQL_CONTAINER_NAME before you call docker stop on it ? If this doesn’t contain anything then that’s the issue, in this case you could either pass the required variables to the shell script and create local variables, or define them hardcoded in the script itself ( your pick ).
Another solution is to pipe the warning of the mysql container to the unix null device by using >> 2>&1 >/dev/null
Do you have a global configuration for bash scripts that kills a bash script after a warning pops up ? If so the warning from mysql will have killed the script when you tried running your last docker exec statement.
No. All I have is set -x
Could you adjust the bash script to print out the value of MYSQL_CONTAINER_NAME before you call docker stop on it ?
The set -x prints out the commands so I know that it’s calling the right container.
The thing is that it’s actually connecting to the container and calling mysql client on it, The client is complaining it can’t reach the mysql in the container.
did u enable the mysql container to accept incoming requests from all IP addresses…
by default mysql ONLY allows connections from application on the same environment
container to container
docker host to docker host
Shouldn’t calling the mysql command via docker exec work though? it says it can’t reach the socket but the docker log shows it’s listening on the socket.
Also if I map a port to the container it should listen right?
if you map and try to access from the docker host(different ip address)
server (mysqld) and client (mysql)
the mysqld (server) by default will listen for connections ONLY in its environment (inside the container)
or inside the docker host…
unless YOU explicitly change that…
you can demonstrate the same problem on a normal system…
on machine A, start mysqld… in a command shell, use mysql and connect. all is good… (localhost:3306)
now go to another machine, and use mysql to connect to the same database you JUST connected to on machine A (machineA:3306…)
boom. you will not be able to connect… cause mysql is listening only for local connections, not over the network. and the user connect request MUST come from the authorized machine…
And i’m guessing that it runs async as a subprocess ? Meaning the command in the script will probably have already completed while in fact the subcomponents where still installing ?