I have a docker container with mariadb, and have created a database my_db in it (through an external script in a different container). How can I run SQL queries on my_db now from the command line? I just want to do
select * from my_table
from the terminal that is running the container.
Easiest way is to exec into the container and execute the query using the mysql client, given the clients installed.
docker exec -it CONTAINER_NAME mysql -p -e 'QUERY' DB_NAME
If you have the commandline tool installed in the app container,
mysql -h 192.168.1.7 -u admin -pxyz -P 10202
This allows for the docker instance to be on another machine (192...) and with a special port (-P ...), etc. (I have multiple docker containers; that one is for MariaDB 10.2.2.)