Through docker-compose.yml I am able to run the application. Now we want to move the application to production, But we don't want to use the container database. So is there any way so that I can connect my local MySQL database with the application using docker-compose?
My docker-compose.yml looks like:
version: '3' services: web-app: build: context: . dockerfile: web-app/Dockerfile ports: - 8080:8080 links: - app-db app-db: build: context: . dockerfile: app-db/Dockerfile environment: - MYSQL_ROOT_PASSWORD=password - MYSQL_DATABASE=Optimize ports: - 3306:3306 Instead of app-db part I just want to connect to my locally hosted mysql database.
Use --network="host" in your docker run command, then 127.0. 0.1 in your docker container will point to your docker host. Note: This mode only works on Docker for Linux, per the documentation.
Just use host.docker.internal instead of localhost.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With