4

I am running 2 docker container with the --net=host option so networking is transparent (docker containers uses the same networking device as host).

    docker network inspect host
[
    {
        "Name": "host",
        "Id": "32ddf8f58d520e49a0b3f296d6d03134b24d7c503309e1c35e04c248010aa64b",
        "Scope": "local",
        "Driver": "host",
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": []
        },
        "Containers": {
            "0e41eb0b07d2751db99a204a3a69a2446bf5b869150bc5741df670e56dbce670": {
                "Name": "sleepy_goldstine",
                "EndpointID": "cc8f2c4da055ae7e608c127552f67753c319aeb603234c418a0ebe8958c1025a",
                "MacAddress": "",
                "IPv4Address": "",
                "IPv6Address": ""
            },
            "71de826121e7222020eec8be8b3a737f3297f8c3aa99d21f0f7016d6aca6f668": {
                "Name": "tender_goodall",
                "EndpointID": "2da0468dbaf1e6b877984cbeb6b2a775786259fec7e83eb373c1d25fe715e16f",
                "MacAddress": "",
                "IPv4Address": "",
                "IPv6Address": ""
            }
        },
        "Options": {}
    }
]

I can access serveral services in the docker containers from outside. However, there is one thing that does not work and I am starting to run with scissors on that...

On the docker host there is a mysql database running on port 3306. No issues with that.

Docker container 1 has as well mysqld running on port 3307 and docker container 2 has mysqld running on port 3308

However, using

mysql -P 3307 -u user -p dbname

I can not access the mysql databases from the host. Even if I provide the port for mysql running in the first docker instance it always directs me to the mysql database on the host. There are no iptables rules in place which could lead to such behaviour. Switching the firewall off doesn't change the behaviour.

In my.cnf the mysql server is bound to 0.0.0.0 (127.0.0.1) doesn't work either.

So I'm getting lost and hope that someone sees a solution. Removing the --host=net option and working with port exposing is not an option because of this decreases the network perfromance into the containers.

Edit: Forgot to mention that the databases within the docker containers are accessible and working as designed. The only thing that doesn't work is the connection from host -> docker because of the connection will be always directed host -> host even using the port from the docker container.

1 Answer 1

5

I guess it has nothing to do with Docker networking. MySQL client just tends to use Unix socket on the host machine exposed by MySQL server. Just provide host IP address to the client, -h 127.0.0.1, to force it to use TCP.

Sign up to request clarification or add additional context in comments.

2 Comments

You are my hero! Solved!
@Blacksheep I'm glad it helped :-) I met this issue many times with SSH tunnelling MySQL port to localhost and always wondered why isn't the damn thing working. Note that it won't work if you provide localhost. Here's a question about how you can configure MySQL client to act in more expected way. And here's a related MySQL bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.