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

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

Related

How to connect remotely to sql database in docker container?

newbie here.
I have a docker container with a mysql server on it. I want to be able to work on it on different pc.
Following a guide I did these steps:
1)create a db and an account with all privileges
2)got the machine ip throudh powershell with:
"docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' YOUR_CONTAINER_NAME"
3)tried to connect to my server in workbench
It didn't work but I don't really know what I'm doing.
Anybody can give me a step by step guide to follow? Thank you
Add port mapping using docker run -p and modify inbound firewall rules in the PC where container is running to allow traffic on the port from another machine in same network

How to connect to MySQL database cluster

I tried to install a MySQL cluster with the Docker image below.
mysql/mysql-cluster - Docker Image | Docker Hub
The Docker image is pulled and run successfully.
Despite that I could connect to the cluster in the terminal (as shown in the screen capture below), I don't know how to connect to it with MySQL Workbench or DBeaver.
In your docker run command, you can use -p 3306:3306 (or any available port). Then you can use <host>:<port> from Workbench or Dbeaver connection URL.
I assume that you already know how to add new DB connection to MySQL Workbench or DBeaver. The information that you want is the connection URL and the username/password of an authenticated user that you need to use to connect to your MySQL cluster.
For the connection URL: 192.168.0.10 (no port in your example)
You need to have your MySQL Workbench or DBeaver connect to the URL of the MySQL node, which is mysql1 node in your example. As shown in your screen capture, it is 192.168.0.10 without any explicit port. But if you have troubles with the URL, you can run docker ps to check what host and port that your mysql1 is running and exposed at.
For the username/password: root/tpffnrtm1 (the password is the value of MYSQL_ROOT_PASSWORD as shown in your docker run of MySQL node command)
I assume that you just want to connect the DB cluster by any means (root or non-root privileges is totally fine for you).

Accessing the host mysql from the docker Container

I have tomcat WAR which I want to run inside a Docker having tomcat image. There is a jdbc java Code in the war which access my local mysql from the docker container. But Docker is not able to connect to the local mysql.
I am able to run my war in tomcat locally. I have changed my my.cnf file bind-address to *.
bind-address = *
How can I configure my jdbc url so that it can connect to local mysql inside the Docker. After googling I came to know about the docker.for.mac.host.internal command map to host ip inside docker. I am not sure how to use it.
You may connect using Unix Domain Socket by mounting:
volumes:
-"/var/run/mysqld/mysqld.sock:/var/run/mysqld/mysqld.sock"
You will also need a compatible JDBC connector, e.g. https://stackoverflow.com/a/31891263/8622794

Howto link a prestashop docker to an existing mysql server

I'm using the following Prestashop docker: https://hub.docker.com/r/prestashop/prestashop/
It so happens that I already have a mysql server running on the host, because that was included with the whole DirectAdmin panel.
The variable DB_SERVER does nothing if I specify localhost or the IP adres of my server. -p 3306:3306 is also not allowed, since that port is already in use.
How can a Docker container reach the host:3306 mysql server?
If I understand correctly, you have your Prestashop installation inside a container and MySQL server running on the Docker host?
Unless configured differently, both the container and the host are in the same bridge network.
Verify that your container is in the bridge network:
docker inspect <container-name>
"Networks": {
"bridge": {
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
}
}
Notice the gateway IP address - this is the address of the docker host inside the bridge network. Use it as a DB_SERVER variable to connect to the MySQL.
One year later...
Like what #NetworkMeister said, but, IPAddress instead.
docker inspect <container-name> | grep IPAddress
In other words, I used 172.17.0.2 and it worked.
I believe what you are looking to do is to connect your container process with mysql server that is running on that host. To retain using localhost as the assignment of DB_SERVER you can do the following...
docker run --net=host <YOUR_CONTAINER_OPTIONS>
By doing this your container will able to reach the mysql service that is deployed on localhost:3306.

Make proxy container for running docker MySQL container

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