I started a container for mysql-server via
docker run --name mysql_server -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mysql
Then I looked up the ip-adress of this container via
docker inspect mysql_server
Afterwards a started a further container to act as mysqlclient (to connect to server) via
docker run -it mysql mysql -h172.17.0.3 -uroot -p
This works fine. But looking up the ip-address every time after starting the mysql-server container is not what i want. So I tried the approach from the docker hub description (https://hub.docker.com/_/mysql) which says that I can pass the mysql-server container name to the -h flag. So I tried the following:
docker run -it mysql mysql -hmysql_server -uroot -p
But the I'm getting the following error
ERROR 2005 (HY000): Unknown MySQL server host 'mysql_server' (-2)
What is a best-practice approach to connect from one 'client' container to a 'server' container? Do I have to specify a fix ip-address when starting the server-container or is there a better generic way