Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR 2005 (HY000): Unknown MySQL server host 'some-mysql' (0) #644

Closed
pcantalupo opened this issue Feb 28, 2020 · 9 comments
Closed

ERROR 2005 (HY000): Unknown MySQL server host 'some-mysql' (0) #644

pcantalupo opened this issue Feb 28, 2020 · 9 comments
Labels
question Usability question, not directly related to an error with the image

Comments

@pcantalupo
Copy link

I'm trying to follow instructions on this page to run docker mysql

$ docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
c365f36e34cd5a580d380f09be3845e84a7a8a741b5a739062d976895d353fb6

$ docker ps | grep some-mysql
c365f36e34cd        mysql               "docker-entrypoint.s…"   27 seconds ago      Up 26 seconds       3306/tcp, 33060/tcp   some-mysql

$ docker inspect bridge | grep -B2 -A5 some-mysql
        "Containers": {
            "c365f36e34cd5a580d380f09be3845e84a7a8a741b5a739062d976895d353fb6": {
                "Name": "some-mysql",
                "EndpointID": "5edbd0af493cad5c8c69525576aab0db8472e7523668104c2b23299053ed9bd6",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            },

Then I'm trying to connect to MySQL from the MySQL command line client with your example code where I replaced some_network with bridge since that is the network some-mysql is on. However I get the following error...why?

$ docker run -it --network bridge --rm mysql mysql -hsome-mysql -u root -p
Enter password: 
ERROR 2005 (HY000): Unknown MySQL server host 'some-mysql' (0)

Thank you

@tianon
Copy link
Member

tianon commented Feb 28, 2020

Docker's built-in DNS doesn't apply on the default bridge network -- it has to be a custom/user-created network for Docker to provide DNS resolution of containers.

@wglambert wglambert added the question Usability question, not directly related to an error with the image label Feb 28, 2020
@pcantalupo
Copy link
Author

Is it possible up update your documentation to make this clearer? Thank you

@wglambert
Copy link

The default bridge network behavior isn't directly related to the image so reproducing Docker's documentation seems unnecessary and out of scope

https://docs.docker.com/network/bridge/#differences-between-user-defined-bridges-and-the-default-bridge

Containers on the default bridge network can only access each other by IP addresses, unless you use the --link option, which is considered legacy. On a user-defined bridge network, containers can resolve each other by name or alias.

Going to close since this is resolved

@martinp999
Copy link

I agree with @pcantalupo - the documentation should say something like -

"To get up and running fast -

  • docker network create mysql-net
  • docker run --network mysql-net --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
  • docker run --network mysql-net -it --rm mysql:tag mysql -hsome-mysql -uroot -p
    "

@wglambert
Copy link

We were using --link in the images examples but changed it from the discussion in #545

docker-library/docs#1441

Ditch a lot of "--link" examples (using "--network some-network" instead to force users to do more homework)

@maaikez
Copy link

maaikez commented Dec 2, 2020

I agree with @pcantalupo - the documentation should say something like -
* docker network create mysql-net
* docker run --network mysql-net --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:tag
* docker run --network mysql-net -it --rm mysql:tag mysql -hsome-mysql -uroot -p

Would be great if this was added to the documentation.

@liranye
Copy link

liranye commented Jan 9, 2021

@martinp999
using your advice I still get the following error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'some-mysql' (113)

[liran@localhost ~]$ docker run --network mysql-net --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql:latest
497ff8aa24ce904230170a51649df8eb96de638baec90ed3510ec3d420f7c7e6
[liran@localhost ~]$ docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
497ff8aa24ce        mysql:latest        "docker-entrypoint.s…"   9 seconds ago       Up 8 seconds        3306/tcp, 33060/tcp   some-mysql
[liran@localhost ~]$ docker run --network mysql-net -it --rm mysql:latest mysql -hsome-mysql -uroot -p
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on 'some-mysql' (113)
[liran@localhost ~]$ 

@martinp999
Copy link

Hi @liranye,

I copied your cli statements (with the addition of an initial docker network create mysql-net) and I got in no problems. The fact that you get asked for a password indicates that the network bridge is working fine. Did you use the correct db pswd (my-secret-pw)?

I am using docker 20.10.2, build 2291f61.

@cas--
Copy link

cas-- commented Oct 5, 2022

I encountered this error while quickly trying to setup mysql. I would expect the documentation to get me up and running not:

force users to do more homework

There is little hint that users need to actually create a network so this is leaving them completely in the dark. Also by the time they come to connect with client using --network option they will need to go back destroy server container and recreate it using custom network...

I am thinking that the next step after starting the server could be an exec command to help users quickly get connected:

docker exec -it some-mysql mysql -p

Otherwise at a minimum for the client instance the wording could be improved

- connected to the `some-network` Docker network
+ connected to `some-network`, a [user-defined Docker network](https://docs.docker.com/network/network-tutorial-standalone/#use-user-defined-bridge-networks)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Usability question, not directly related to an error with the image
Projects
None yet
Development

No branches or pull requests

7 participants