Connecting to mysql server from docker container [duplicate] Connecting to mysql server from docker container [duplicate] docker docker

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:

  1. 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.
  2. Start a new container running mysql:latest image and use docker-compose to start both.
  3. 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.