Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

berito/spring-boot-mysql

Repository files navigation

Spring Boot on Docker connecting to MySQL Docker container

  1. Use MySQL Image published by Docker Hub (https://hub.docker.com/_/mysql/) Command to run the mysql container docker run --name mysql-standalone -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=test -e MYSQL_USER=root -d mysql:5.6

  2. In the Spring Boot Application, use the same container name of the mysql instance in the application.properties spring.datasource.url = jdbc:mysql://mysql-standalone:3306/test

  3. Create a Dockerfile for creating a docker image from the Spring Boot Application FROM openjdk:8 ADD target/users-mysql.jar users-mysql.jar EXPOSE 8086 ENTRYPOINT ["java", "-jar", "users-mysql.jar"]

  4. Using the Dockerfile create the Docker image. From the directory of Dockerfile - docker build . -t users-mysql

  5. Run the Docker image (users-mysql) created in #4. docker build . -t users-mysql

Useful Docker commands

  • docker images
  • docker container ls
  • docker logs <container_name>
  • docker container rm <container_name
  • docker image rm <image_name

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published