Accessing local MySQL server from my docker container
Clash Royale CLAN TAG#URR8PPP
Accessing local MySQL server from my docker container
I have a mysql server and a docker container running on my machine. In the docker container, I run a django website. I want to connect to the local mysql server from the docker container. How can I do that?
Possible duplicate of From inside of a Docker container, how do I connect to the localhost of the machine?
– David Maze
Aug 12 at 14:04
1 Answer
1
I usually do ( for testing purposes ) :
docker network create -d my-bridge
docker run --network my-bridge --name app-db -e MYSQL_ROOT_PASSWORD=secret -e
MYSQL_DATABASE=myapp -e MYSQL_USER=myapp_user -e MYSQL_PASSWORD=myapp_secret
mysql:latest
docker run --network my-bridge --name app -p 80:80 -e DB_HOST=app-db -e DB_USER=myapp_user -e DB_PASS=myapp_secret -e DB_NAME=myapp myapp:latest
In my app Dockefile I am using in entrypoint something like envsubst, or if code language can read from environment variables I dont need to setup this.
Forget about --link
docker parameter -> its obsolete
--link
when I tried the 2nd command, I got an error like
ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'
– Abhinav Manoj
Aug 15 at 16:11
ERROR 1396 (HY000) at line 1: Operation CREATE USER failed for 'root'@'%'
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
can you add your docker-compose file?
– JPG
Aug 12 at 12:58