MariaDB / mariadb-docker

Docker Official Image packaging for MariaDB
https://mariadb.org
GNU General Public License v2.0
770 stars 438 forks source link

Client connection example doesn't work for MariaDB 10.1, returns error #283

Closed hbielenia closed 4 years ago

hbielenia commented 4 years ago

Following instructions on https://hub.docker.com/_/mariadb, I do the following:

  1. Start container with docker run --name mariadb -e MYSQL_ROOT_PASSWORD=pass mariadb:10.1
  2. Check the container's network with docker inspect mariadb, I see it connects to default bridge network:
    "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "055e66b9aa07fa3e3f9a34c76612fd6b3b7b0d2ab2ca25364b43aa0be18ec7db",
                    "EndpointID": "14a3e502341080dd8609f2f6fe64b77c387e66749d54f2a6f327f7c2e1792e33",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
  3. Try to connect to working container with docker run -it --network bridge --rm mariadb:10.1 mysql -hmariadb -uroot -p, I get the password prompt and after filling in pass, I get the error: ERROR 2005 (HY000): Unknown MySQL server host 'mariadb' (-2)
wglambert commented 4 years ago

The default Docker bridge network doesnt allow for inter-container hostname resolution, you want a user defined one 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.