How to connect already running mariadb container

Sathish David  Kumar N
Sathish David  Kumar N used Ask the Experts™
on
How to connect already running mariadb container

I found this query

$ docker run --name appName --link some-mariadb:mysql -d application-that-uses-mysql

i am confuse with the syntax ?
can any one tell me how to use this ??
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Prabhin MPDevOps Engineer
Distinguished Expert 2018

Commented:
docker run --link
will link the other container.
for more understanding please find the following link, an example of WordPress docker container uses MySQL container.
https://www.deploycontainers.com/2017/12/29/running-wordpress-mysql-docker-containers/

Hope this info help you
its gd example but wordpresshost all are different is any other example link mariadb
Prabhin MPDevOps Engineer
Distinguished Expert 2018

Commented:
use mariadb instead of mysql.

if didn;t get what do you mean "wordpresshost all are different "
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

actually I am not going to use wordpress so we cant use wordpresshost  and wordpressDBname .
is there any noraml host and db name like syntax ?

I tried but its not working
David FavorFractional CTO
Distinguished Expert 2018

Commented:
Sounds like you may be using some sort of hosting which provides docker containers as App wrappers (shudder...) so, if this is the case, best to ask your hosting company for assistance, as they'll better understand their own infrastructure.

And for the question How to connect already running mariadb container the answer is fairly simple.

You expose a port in your /etc/mysql/my.cnf file (or your Distro's equivalent) which external process can access.

You'll also create a GRANT on the MariaDB database to allow an external host (or IP) + user + pass to connect to your exposed port.

Keep in mind, all data will be clear text, unless you wrap this connection with either internal MariaDB SSL or an external facility like stunnel.

If you're trying to actually connect from another container to the MariaDB container's database unix domain socket, this can be super complex. Another question for your hosting company.
Prabhin MPDevOps Engineer
Distinguished Expert 2018

Commented:
then create the variable for username , password , host and pass the inputs while docker run command.
mysql -u sathish  -pxxxx --host xxxx.ci9m4obirg2u.us-west-2.rds.amazonaws.com -P 3306  --socket=TCP/IP  -e "USE myDB; insert into myDB.TestTable values(50000);"

This is working fine in awscli but while using in docker its giving error message !!
Mysql is not found .

Shall i use downlaod mysql-client image and directly use that or ?
We need to use docker run for that image ??
mysql client Image i have used
David FavorFractional CTO
Distinguished Expert 2018

Commented:
To clarify your answer.

Likely the fix was to install the mysql-client or mariadb-client package inside your container.

And also, this isn't necessary. You could just install the client package at the machine level + connect to your container from the machine level.

This will reduce container size, so if you have many containers, installing a machine level client package means only one copy of this package installed, rather than 100s or 1000s of copies, if you have many containers.
maria db client

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial