How to connect already running mariadb container

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 ??
LVL 20
Sathish David  Kumar NArchitectAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Prabhin MPDevOps EngineerCommented:
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
Sathish David Kumar NArchitectAuthor Commented:
its gd example but wordpresshost all are different is any other example link mariadb
Prabhin MPDevOps EngineerCommented:
use mariadb instead of mysql.

if didn;t get what do you mean "wordpresshost all are different "
Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Sathish David Kumar NArchitectAuthor Commented:
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 FavorLinux/LXD/WordPress/Hosting SavantCommented:
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 EngineerCommented:
then create the variable for username , password , host and pass the inputs while docker run command.
Sathish David Kumar NArchitectAuthor Commented:
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 ??
Sathish David Kumar NArchitectAuthor Commented:
mysql client Image i have used

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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.
Sathish David Kumar NArchitectAuthor Commented:
maria db client
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MariaDB

From novice to tech pro — start learning today.