0

I recently installed Docker in Ubuntu 18.04 and with that, I have downloaded the mariadb image like this

docker run --name mariadb \
-p 3306:3306 \
-v /opt/mariadb_data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=lopaz \
--restart always \
-d mariadb:10.1

this is pretty cool method that I used to download from the official mariadb image and it's working well. What my question is that I want to use to login to the MariaDB ? when I type

mysql -h <myhost> -u root -p

MySQL or MariaDB not found on my local Ubuntu machine. What happened ? how my pc knows that I installed mariadb using docker? then I installed mysql client app then only I can use mysql commands on my local pc! please give me a clarification about why it happens when install using docker?

2

When you download mariadb image, mysql client tool is only available inside container. It is not getting magically installed on your local - that is why you had to install mysql client app.

Alternative way to connect to db without installing mysql app is to use docker exec and through this get to mysql tool available on container. So you would do something like:

docker exec -it your_maria_db_container_id mysql -h localhost -u root -p

Hope this helps.

1
  • 1
    Thanks it works . Now I can run mysql commands within container . – soldier Feb 29 '20 at 2:53

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.