Our tomcat-application was using a application-dev.yml file with jdbc config variable to connect to the mysql, say something like url: jdbc:mysql://db:3306/abcDB?useUnicode=true&characterEncoding=utf8&useSSL=falseĬommand: '-default-authentication-plugin=mysql_native_password'Īs we wanted to connect our docker-compose tomcat service from the local mysql we tried the below routes.ĭocker inspect | grep Gateway which returned the ip Gateway ip value as` "Gateway": "", So as alternative and quick fix we thought to use local mysql configured on the local laptop with Ubuntu and docker-compose. We had a same scenario where we wanted to setup a Development local machine setup for the services where a developer can just make docker-compose up -d and use all the latest dev builds in his local machine.īut we started facing issues while connecting our tomcat based web service configured as service in the docker-compose.yml to **mysql-8.0** service within the docker-compose. Then, point in your hibernate.properties to mysql as this: localhost:3306 In your my.cnf search for bind-address that should be 0.0.0.0 (consider security issues if your server has public IP).Īs an alternative you can bring to the container the same networking as your host, in order to share the localhost, so the container will find mysql there. Take into account that that IP is fixed as long as the docker network still the same (the network is created by docker-compose, and it is not removed unless you do docker-compose down)Īlso, check that your MySQL is listening to all of its interfaces. So inside your docker application point to MySQL as this: 172.18.0.1:3306 (maybe in a configuration file). If you use docker-compose.yml version: "3" it's probably that that IP is: 172.18.0.1, but confirm it searching for the "Gateway" of your container (your host): docker inspect | grep Gateway You can also share a volume between the server and host to make it easier to import data or scripts.Find the host machine ip in the docker network. This last container will remove itself when you exit the mySQL interface, while the server will continue running. This approach gives me the chance to start mysqld and bind it to 0.0.0.0 (all IPs).įor details, please refer to these lines in my GitHub repo. Instead, I made my own by installing MySQL on Ubuntu 18.04. To make the demo self-contained, I moved all necessary code to. Same advice as maniekq but full example with docker-compose. The password is "wp" which is defined in the docker-compose.yml file. You can pass the -d flag to run the mysql/mariadb container in detached/background mode. Type '\c' to clear the current input statement. Other names may be trademarks of their respective Oracle is a registered trademark of Oracle Corporation and/or itsĪffiliates. Server version: 5.5.5-10.1.19-MariaDB-1~jessie binary distributionĬopyright (c) 2000, 2016, Oracle and/or its affiliates. $ mysql -P 8083 -protocol=tcp -u root -p Enter password: Now, you can access the mysql console thusly: Here's how that would work:Ĭreate a file named, docker-compose.yml that looks like this: version: '2' And I can see in the container /var/log/mysql/error.log: But when I attach my image, I can observe it actually worked as expected (ie: removed the bind-address). Admittedly, there may be cleaner way to do it. I've seen that there are images dedicated to mysql, but I didn't have more success with them.However, it isn't the same (and it doesn't have any answers anyway) I've seen that there's a question which looks like mine.However I don't have that much success from the host: > mysql -P 12345 -urootĮRROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) When I attach to the image, it seems to work just fine: # from the host In the directory where there is this file, I can succesfully build the image and run it with: > docker build -t my-image. # It doesn't seem needed since I'll use -p, but it can't hurtĬMD /etc/init.d/mysql start & tail -F /var/log/mysql.log RUN grep -v bind-address /etc/mysql/my.cnf > temp.txt \ RUN apt-get update & apt-get install -y mysql-server I'm using the following Dockerfile: FROM ubuntu:14.04.3 So far, the best I have achieved is: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) I want to run mysql in a docker container and connect to it from my host.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |