This seems not wholly unreasonable:

root $ 
root $ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
root $ 
root $ docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
e57e2c862b19        bridge              bridge              local
94f944a05b0e        foo                 bridge              local
25aba55a5413        host                host                local
ad5c1c2fa1e1        none                null                local
root $ 
root $ docker run --name mysql --network foo  -tide  MYSQL_ROOT_PASSWORD=password mysql/mysql-server:latest
root $ 
root $ docker run -itd --name alpine --network foo alpine
root $ 
root $ docker exec -it alpine sh
/ # 
/ # ping mysql
PING mysql ( 56 data bytes
64 bytes from seq=0 ttl=64 time=0.200 ms
64 bytes from seq=1 ttl=64 time=0.115 ms
64 bytes from seq=2 ttl=64 time=0.115 ms
--- mysql ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.115/0.143/0.200 ms
/ # 
/ # 
/ # mysql mysql -h mysql -P 3306 --protocol=tcp -u root -p
sh: mysql: not found
/ # 

but, if mysql isn't recognized as a command, probably alpine is a bit too lightweight. What would be a more reasonable image from the docker hub to grab for connecting to the MySQL container from another container?

I also tried:

root $ 
root $ docker run --name alice --network foo  -tide  MYSQL_ROOT_PASSWORD=password mysql/mysql-server:latest
root $ 
root $ docker run --name bob --network foo  -tide  MYSQL_ROOT_PASSWORD=password mysql/mysql-server:latest
root $ 
root $ docker exec -it alice bash
bash-4.2# hostname
bash: hostname: command not found
bash-4.2# host
bash: host: command not found
bash-4.2# whoami
bash-4.2# ping bob
bash: ping: command not found
bash-4.2# telnet bob
bash: telnet: command not found
bash-4.2# mysql mysql -h bob -P 3306 --protocol=tcp -u root -p
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on 'bob' (111)

I suppose I can use a more general purpose container and install the MySQL cli client, but would rather use a docker image from the hub.

  • 1
    There are some mysql-client images available such as this one. Have you checked them? – seshadri_c Sep 27 '20 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.