My main question is that after I have created a docker container for my mariadb with the command docker run --name db -e MYSQL_ROOT_PASSWORD=test -d -p 3306:3306 mariadb
how can I access the sql db?
Somewhere I have seen a solution using a temporal (after exit the container is deleted) container, but cannot find it anymore.
I am searching for a command like: sudo docker exec -it [other flags] [command] db
.
Install the mysql client on your host,
apt-get install mysql-client
then use the following command to access your database container.
mysql -u<user> -p<pass> -h $(docker inspect --format '{{ .NetworkSettings.IPAddress }}' <db-container>)
The command will automatically get the IP of your docker container.
Make sure to replace <user>
, <pass>
and <db-container>
with your respective values. In your case:
mysql -uroot -ptest -h $(docker inspect --format '{{ .NetworkSettings.IPAddress }}' db)
Your command lets mariadb run at the standard port 3306. If not, you have to tell the mysql command the new port.