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 2

    I did this with postgresql , I need to:

    1. configure the docker so that the bridge which it does by default docker0 a known ip address 172.17.42.1 (I do not remember the details, but is it possible that the docker is configured by default?)

    2. to register in a config that mysqld listened 172.17.42.1 with the help bind-address=

    3. Make sure that mysqld starts the docker later - it depends on what it uses in the system. I had init.d + upstart , so I just added a loop to bash ifconfig | grep docker0 ifconfig | grep docker0

    4. It is possible to correct iptables rules 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