0

I am trying to access the MySQL database in the Docker container but is not allowing me to access it.

The Mysql database is running on my local machine.

I tried with docker run --network="127.0.0.1" -it -p 8080:8080 but no luck

my docker file

FROM tomcat:latest
ADD target/sample.war /usr/local/tomcat/webapps/
EXPOSE 8080
CMD ["catalina.sh", "run"]
Ganesh Gudghe
  • 1,129
  • 12
  • 32
  • Could you check if this answer works for you https://stackoverflow.com/a/43541732/1336841 – Sergei Jan 21 '21 at 06:15
  • Check the [documentation](https://docs.docker.com/compose/compose-file/compose-file-v2/#links) you have two options, to use links, or using networks. AFAIK you are using flag --network in the wrong way – AngeLOL Jan 21 '21 at 06:19

1 Answers1

0

In your container, to connect to host machine, you will use host.docker.internal.

In your case it'll be host.docker.internal:3306 (mysql)

Duc Trung Mai
  • 733
  • 1
  • 6
  • 13
  • not working for me, i also tried setting MySQL bind-address = 0.0.0.0 and docker run --network=host -h 127.0.0.1 b0fbd48de7d7 but same issue – Ganesh Gudghe Jan 21 '21 at 11:50