Avatar of Sathish David  Kumar N
Sathish David Kumar NFlag for India

asked on 

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 ??
* MariaDBJavaDockerAWSAWS RDS

Avatar of undefined
Last Comment
Sathish David Kumar N
Avatar of Prabhin MP
Prabhin MP
Flag of India image

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
Avatar of Sathish David  Kumar N

ASKER

its gd example but wordpresshost all are different is any other example link mariadb
Avatar of Prabhin MP
Prabhin MP
Flag of India image

use mariadb instead of mysql.

if didn;t get what do you mean "wordpresshost all are different "
Avatar of Sathish David  Kumar N

ASKER

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
Avatar of David Favor
David Favor
Flag of United States of America image

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.
Avatar of Prabhin MP
Prabhin MP
Flag of India image

then create the variable for username , password , host and pass the inputs while docker run command.
Avatar of Sathish David  Kumar N

ASKER

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 ??
ASKER CERTIFIED SOLUTION
Avatar of Sathish David  Kumar N
Sathish David Kumar N
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of David Favor
David Favor
Flag of United States of America image

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.
Avatar of Sathish David  Kumar N

ASKER

maria db client
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo