On centos, mysql is running locally and a web server is installed in docker compose with ubuntu 14.04. How can I connect from the docker to the mysql server running locally on the server?
2 answers
I did this with postgresql , I need to:
configure the
dockerso that the bridge which it does by defaultdocker0a knownipaddress172.17.42.1(I do not remember the details, but is it possible that the docker is configured by default?)to register in a config that
mysqldlistened172.17.42.1with the helpbind-address=Make sure that
mysqldstarts thedockerlater - it depends on what it uses in the system. I hadinit.d + upstart, so I just added a loop tobashifconfig | grep docker0ifconfig | grep docker0It is possible to correct
iptablesrules so that it does not chop packets (if the settings are not paranoid, then usually this step is not needed)
Everything is now out of the container can be addressed at 172.17.42.1 to mysql
A rather elegant solution is to mount the socket file created by mysqld inside the container :
$ docker run ... -v /путь/на/хосте/к/mysqld.sock:/путь/в/контейнере/к/mysqld.sock ... or, since you are using docker compose , using the appropriate lines in the compose file.
the path can be, for example, “peep” in the mysqld configuration:
$ grep -r socket /etc/mysql* - Thank. Great way. But it doesn’t quite fit me, as in this case I need access not only to mysql - Vladimir