0

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
e85d7d980f88eac37f15760d2dc30ca6545214ba52e82dc24a1df8664a4de915
root $ 
root $ docker run -itd --name alpine --network foo alpine
262b238272f756b90b9735f826234e34d4b05fcdb88416c15947ed3383281739
root $ 
root $ docker exec -it alpine sh
/ # 
/ # ping mysql
PING mysql (172.21.0.2): 56 data bytes
64 bytes from 172.21.0.2: seq=0 ttl=64 time=0.200 ms
64 bytes from 172.21.0.2: seq=1 ttl=64 time=0.115 ms
64 bytes from 172.21.0.2: seq=2 ttl=64 time=0.115 ms
^C
--- 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
4ebb217b18abe78d35a4cd08d253e45d089083776f86f52da77f04a8c97de01e
root $ 
root $ docker run --name bob --network foo  -tide  MYSQL_ROOT_PASSWORD=password mysql/mysql-server:latest
856d398fe7ed472698127c8d4a07fce9aa50d48d79587bd731c973ee17e4dde9
root $ 
root $ docker exec -it alice bash
bash-4.2# 
bash-4.2# hostname
bash: hostname: command not found
bash-4.2# 
bash-4.2# host
bash: host: command not found
bash-4.2# 
bash-4.2# whoami
root
bash-4.2# 
bash-4.2# ping bob
bash: ping: command not found
bash-4.2# 
bash-4.2# telnet bob
bash: telnet: command not found
bash-4.2# 
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)
bash-4.2# 

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
  • 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.