-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connecting to a mysql running on a Docker container #95
Comments
It looks mysql interpreting the
|
By any chance did you get this to work? I have a docker container that runs mysql, but i cannot figure out what the settings are in sequel pro to get it to connect. What credentials are needed? |
@flacoman91 how are you running your container (i.e., arguments to docker run, or docker compose service)? |
@helderco
Running docker ps i get |
You need to publish your mysql port to your host. The port can be a specific one or random. If random use Since you're using Sequel Pro, I guess you're using a Mac, with a VM for docker server. If you're using docker-machine, you can get the IP address with Credentials (Standard connection in Sequel Pro): Host: IP of your docker machine host Example for random host port (avoids conflict with other projects):
I actually use a script to open directly in Sequel Pro from the command line. You can get it at https://gist.github.com/helderco/e9d8d072a362ad818f6a This is how I use it:
It launches a new window already opened in that database in my container. Note that I assume password is root (my convention in development). It also assumes you use docker-machine. The database is optional, and you can set the other credentials manually with arguments. |
THANK YOU THANK YOU! That worked. i missed the step where you said: If you're using docker-machine, you can get the IP address with docker-machine ip . I kept putting in the ip for the individual container, and not the docker host, which in my case is just the default or 192.168.99.100 and the port was the randomly assigned one which was found through |
Struggled with this for ages until I realised I was entering http://my-docker-ip-address instead of just my-docker-ip-address. Remove that http! |
Hi, I have this container: $ docker ps And i run Getting I've tried with Container ID and have the same response. ¿How can I get the specific IP of the shopapp-mysql container? |
You're trying to use docker machine in a container, which are different tools. Try:
|
I've tried that too, it give me a IPAddress=172...... I try to connect to that IP from an mysql client but I get conection timeout.... |
I assume you use docker machine with Mac or Windows. Just find the forwarded port with:
And your docker machine IP with:
Now point your mysql client to (example): Note: The 3306 port needs to be exposed, which from your |
thanks @helderco !! I have run my container exposing the port to my PC
And that works! |
In this Dockerfile, a "mysql" user is created but there is no "USER mysql" instruction. So why, when you run the image without "-u" or "--user" mysqld is running as "mysql" and not as "root" ? |
@TristanCP, the entrypoint script drops to the mysql/8.0/docker-entrypoint.sh Lines 62 to 67 in 64e0cf2
|
It should also work with |
@dslopez @helderco I was going through your conversation and the rest of it in this issue but could not find a solution to my issue. I have followed the https://hub.docker.com/_/mysql/ to setup a mysql container. So I did something like this Then I have the app which is another container itself and link it on runtime by doing this So I did
Any suggestion or idea what I am doing wrong? Ideally I would like to do using docker-compose but I want to know why this way is not working. |
@ssh24, if you are on Windows or OSX using docker-machine/boot2docker, you won't be able to connect directly to a container's IP address from the host. You would need to start the container with In the application that uses mysql how are you connecting to the mysql service? In other words, are you connecting to |
@yosifkit I was not using I just tried this to connect to the mysql client locally after spinning up the container and still won't work. The IP address of the
|
@ssh24 Are you running on Windows or Mac? If running on Windows or Mac the containers are created on a virtual machine. That is, the host of the containers is the virtual machine not your actual machine. So find out which is the IP of the docker VM and use it instead of 172.17.0.2 |
@ssh24 you need to do a
to obtain the IP address of your container. |
I just found out I can connect SequelPro to a MySQL server on Docker with these data: (no need for the IP of the server)
I posted my configuration here: http://andowebsit.es/blog/noteslog.com/post/how-to-install-wordpress-with-docker-on-os-sierra/ |
@aercolino came here to say that switching my local mysql instance from 3306 port to 32768 fixed my issue with connect to it through SequelPro. Good looking out there dude! |
I have problem to set up mysql but i realized that i try connect to EARLY (!) If I make |
@dslopez , after running "docker-machine ip" it is giving error the result of the command "docker port mysql_container 3306" is : 0.0.0.0:3306 |
FYI, this may not be as easy as using the docker host IP (it did NOT work for me), even if you have defined the port (3306). Look in the compose file and all config files in etc, because in the case below, OUTSIDE of the container, on my local LAN, in a webpage being served from the docker host, instead of localhost, or any IP, I was required to enter the word "DATABASE" (http://database:3306) because THAT is what was defined in the config file as the dbhost......and it actually worked.
|
Facing a similar problem using Docker on Mac:
|
Try "127.0.0.1" for "--host" instead of "0.0.0.0".
|
I have tried that with no success
|
This worked for me. docker run -it -v --name mysql-server -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=demo mysql |
Not sure what happened overnight, but ran the same command this morning and it works! |
Hi, and on Heidisql (Windows): |
@aercolino when i click your link below, the page was not found. |
my solution with mysql 5.7.x
MySQLWorkbench config
nodejs mysql
|
|
@Samurais 嗯。https://github.com/mysqljs/mysql 的REAEME.md是这么写的,我直接复制过去的测试用的。 |
docker run --name=[name] -p 3306:3306 --rm -e MYSQL_ROOT_PASSWORD=[password] mysql:latest docker exec -it [name] /bin/bash mysql -u root -p |
Mysql service configuration
Connect to the container:
To connect to mysql on your container:
The password is the env variable MYSQL_ROOT_PASSWORD After logging into mysql on your mysql container, run this command:
You get the message: Query OK, 0 rows affected (0.00 sec) You can now go to Sequel Pro and connect to your mysql container. Or simply add this command to your mysql service config in docker-compose.yml
|
I'm trying to run mysql server on a Docker (installed with Docker Toolbox for Mac) container and access it from my machine running OS X Yosemite. The documentation from the official repo does not explain how to connect from outside the docker host !!
I've created a container using the official repository as follows:
Then I get the ip address (172.17.0.1), but when I ping it I see time outs!!!
I tried to add port forward to the
default
machine:But when connecting with Sequel pro (a mysql client) with [email protected] on 3306, I have a connection failure.
What's the appropriate way to connect to the running mysql server?
The text was updated successfully, but these errors were encountered: