https://github.com/techprimers/docker-mysql-spring-boot-example
Spring Boot on Docker connecting to MySQL Docker container
https://github.com/techprimers/docker-mysql-spring-boot-example
Last synced: over 1 year ago
JSON representation
Spring Boot on Docker connecting to MySQL Docker container
- Host: GitHub
- URL: https://github.com/techprimers/docker-mysql-spring-boot-example
- Owner: TechPrimers
- Created: 2017-12-08T16:52:22.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-01T14:39:47.000Z (about 6 years ago)
- Last Synced: 2025-04-15T06:54:33.740Z (over 1 year ago)
- Language: Shell
- Size: 55.7 KB
- Stars: 48
- Watchers: 6
- Forks: 150
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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=password -e MYSQL_DATABASE=test -e MYSQL_USER=sa -e MYSQL_PASSWORD=password -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 `
- `docker container rm