Skip to content

Can't connect with mysql-cli from host to mysql docker container #527

Closed
@keltik85

Description

@keltik85

Hi,

I did the following to start a MySQL docker container:

docker run --name=my_mysql_instance -d mysql/mysql-server:latest

I verified that its running with:

docker ps -a

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS                    PORTS                 NAMES
92de8d5bdb67        mysql/mysql-server:latest   "/entrypoint.sh mysq…"   About an hour ago   Up 10 minutes (healthy)   3306/tcp, 33060/tcp   my_mysql_instance

And also logged in to the conainer with:

docker exec -it my_mysql_instance mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 32
Server version: 8.0.13

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

What i could not achieve is connecting through the docker HOST mysql-cli to the docker container like this:

mysql -h localhost -P 3306 -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2

This did not work either:

mysql -h 127.0.0.1 -P 3306 -u root
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

This did also not work:

mysql -h localhost -P 3306 --protocol=tcp -u root
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (111)

I found out the ip of the docker container over the docker bridge:

docker inspect my_mysql_instance | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.2",
                    "IPAddress": "172.17.0.2",

But using the IPAdress did also not work:

mysql -h 172.17.0.2 -P 3306 --protocol=tcp -u root
ERROR 1130 (HY000): Host '172.17.0.1' is not allowed to connect to this MySQL server

Am I too stupid to use docker or did I get something conceptually wrong or something else.

Thanks for enlightenment!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionUsability question, not directly related to an error with the image

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions