Connecting to mysql server from docker container [duplicate]
openjdk:8
docker image does not provide a MySQL database running on localhost:3306
. There are few ways you can approach your problem:
- Configure JDBC URL to point from docker container to a host machine if you are running MySQL on host. See this answer to understand how to do this.
- Start a new container running
mysql:latest
image and usedocker-compose
to start both. - Add MySQL to your docker image (not recommended, option 2 is preferred).
As you are starting go with option 1 and try to understand difference between container and host.
If you are doing this to learn docker I'd suggest to do all 3 options one by one and understand what are the differences. It would be a worthwhile exercise.