Make proxy container for running docker MySQL container - mysql

I have running docker MySQL container on production server.
I need to connect to MySQL database from another server.
Container just have EXPOSE 3306, but no binded ports.
So, i understand that binding port to a running container is not possible.
I thinking about creating new "proxy" container, bind ports to listen outside and link it to existing MySQL container.
Will this work?
Sorry for my english

Just run your container with -P option or with -p <host_machine_port>:<container_port>
For MySQL it can be done with docker run -p 3306:3306 mysql
And you can connect to MySQL through yourmysqldomain.com:3306

Related

initialize mysql in host and access in docker container

I am creating very simple database like
mysql -u root -e "CREATE DATABASE IF NOT EXISTS example"
and I want to access it in the doker container like
"mysql://root#localhost/example"
both host and conteiner is ubuntu machine
I suppose answer is very simple but I got lost - Thanks !
With docker, all the stuff can be accessible with localhost. But you need to expose the service to a local port.
So with -p 80:80 in your run command, you will be able to expose the port 80 on your container, to your local port 80.
Docker run doc
I hope it will help you!

Can't connect to MariaDB Docker Container

I have MariaDB running on docker. Bind address is commented out in the my.cnf file and everything appears set. I know what the IP address is and am currently trying to force the TCP connection (I am using this resource: https://mariadb.com/kb/en/installing-and-using-mariadb-via-docker/). I also have a java program in another docker container that is able to access the container - I just need to access the container myself to load some SQL. Any advice as to why it isn't connecting?
I am running this command right now (with the correct IP):
mysql -h 172.17.0.2 -P 3306 --protocol=TCP -u root -p
The documentation (soon to be fixed), misses -p 3306:3306 on the parameters when the container is run to expose the 3306 in the container to the host.
Recommend for next question explicitly show how the container was run, the docker inspect command used to derive your IP address, and the actual failure the mysql command line showed.

How to access mysql databases inside docker from a SQL GUI?

I am using vessel to run my Laravel project.
As I understand it basically simply creates a put-together docker image of my laravel project with mysql and everything.
Now since its running in docker, is it possible for me to access the mySQL databases with datagrip or tableplus on my host machine?
You just need to expose a port via docker. If you dont,you will have port 3306 which can be accessed via the local containers but if you bind port 3307:3306 for instance you can connect to mysql locally on 3307
you will need to connect to MySQL server using the docker containers IP that can be found using docker inspect.
This can also help you:
https://towardsdatascience.com/connect-to-mysql-running-in-docker-container-from-a-local-machine-6d996c574e55

Runing multiple mysql containers with different port using host network

I have a Mysql server running on the host using default port 3306. I Want to run a MySQL docker container using network host but with a different port.
My configuration is defined in a docker-compose file. After building the image and tried running the container, it starts and shutdown with port conflict notice.
Is there a way to dynamically change the container port before starting up? I don't want to use the network bridge.
If using host networking is a hard requirement, then nothing in Docker space will be able to control or limit what ports the service does or doesn't use. You need to change a service-specific configuration file, environment variable, or command-line argument to make it listen somewhere else.
Particularly for servers that listen on a single TCP port (like most database and HTTP-based servers) the default Docker bridge/NAT setup should work fine; alternate setups like host networking and macvlan are unnecessary. If you're willing to use the standard setup, this is trivial:
version: '3'
services:
mysql:
image: mysql
ports: ['9999:3306'] # listen on host port 9999 instead
docker run --name 'dockername' -e MYSQL_ROOT_PASSWORD='password' -p 1000:3306 -d mysql
docker exec -it 'dockername' mysql -uroot -p
ALTER USER 'root' IDENTIFIED WITH mysql_native_password BY 'password'
flush privileges;
here 1000 is the port at which you want to run your mysql docker container.

docker.io - Connecting to MySQL with Scala

I am new to Docker. Currently, I am trying to connect my Scala container with a MySQL container but just can't find any resources on how I can do it. Is it able for me to create a JDBC connection on the Scala container and connect to the MySQL container using the linking method?
https://docs.docker.com/userguide/dockerlinks/#docker-container-linking
http://www.javacodegeeks.com/2014/12/wildflyjavaee7-and-mysql-linked-on-two-docker-containers-tech-tip-65.html
mysql runs on a port.The default port for this is 3306.
This port on your mysql container should be exposed by adding EXPOSE 3306 in dockerfile.
For best results use official mysql image from docker hub (https://registry.hub.docker.com/_/mysql/ )
use -h"$MYSQL_PORT_3306_TCP_ADDR" in your scala container.
Eg: mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -u -p
This should do the trick!!