This repository contains a sample Spring Boot application connected to a MySQL database using Docker Compose. It demonstrates how to set up a development environment for a Spring application along with a MySQL database using Docker volumes.
Before you begin, ensure you have the following installed:
- Docker: Install Docker
- Docker Compose: Install Docker Compose
-
Clone this repository:
git clone https://github.com/your-username/your-spring-mysql-app.git cd your-spring-mysql-app
- Replace your-spring-app-image:tag with the actual image and tag of your Spring Boot application.
- You can use the
docker-compose up --build
command to automatically build the specified tag related image mentioned in the docker-compose file.
docker-compose up
- This command will start the Spring Boot application and the MySQL database. It will create a Docker network to connect the services.
-
Spring Applicatiion:
- Host: localhost
- Port: 8080
-
MySQL Database:
- Host: localhost
- Port: 3306
- Username: springuser
- Password: spring_password
- Database: springdb
- Testing end points
- Save the employee
{
"id": 1,
"name": "supun",
"age": 33
}
- Get All employees
- When you're done, stop the application using:
docker-compose down
- To observe the container volume qualities check the db container restart, Data still remain:
docker restart <mysql_container_id>
- This command will stop and remove the containers, but your data will persist in the Docker volumes.
- The Spring Boot application's configuration can be found in the application.properties file. Update the database connection properties as needed.
- The MySQL data is stored in Docker volumes, ensuring that the data persists even if containers are stopped and restarted.
- Make sure your Spring Boot application connects to the database using the appropriate configuration.
- For production deployments, consider more secure practices, such as using environment variables for sensitive data.
- This project is licensed under the MIT License.