Skip to content

[docs]: Docker-Compose Setup for MySQL #12

@0PrashantYadav0

Description

@0PrashantYadav0

Description

  • Detailed Description:
    Containerizing the MySQL database simplifies development and ensures a consistent environment. Students should create a docker-compose.yml file to spin up a MySQL container and update the Spring Boot configuration to use this database.
  • How to Solve:
    1. Create a docker-compose.yml File:
      Place the file in the project root with the following content:
      version: '3.1'
      services:
        mysql:
          image: mysql:8.0
          restart: always
          environment:
            MYSQL_DATABASE: stoxsdb
            MYSQL_USER: user
            MYSQL_PASSWORD: password
            MYSQL_ROOT_PASSWORD: rootpassword
          ports:
            - "3306:3306"
    2. Update application.properties:
      Configure the datasource to point to the MySQL container:
      spring.datasource.url=jdbc:mysql://localhost:3306/stoxsdb
      spring.datasource.username=user
      spring.datasource.password=password
      spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
      spring.jpa.hibernate.ddl-auto=update
    3. Run Docker Compose:
      Execute docker-compose up from the command line to start the MySQL container.
    4. Verify Connectivity:
      Start your Spring Boot application and verify that it connects successfully to the MySQL database.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions