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
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.
Is it possible up update your documentation to make this clearer? Thank you
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
I agree with @pcantalupo - the documentation should say something like -
"To get up and running fast -
We were using --link in the images examples but changed it from the discussion in https://github.com/docker-library/mysql/issues/545
https://github.com/docker-library/docs/pull/1441
Ditch a lot of "--link" examples (using "--network some-network" instead to force users to do more homework)
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.
@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 ~]$
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.
Most helpful comment
I agree with @pcantalupo - the documentation should say something like -
"To get up and running fast -
"