I am learing Docker and encountered an error is that I have created a basic CRUD springboot application which create,getById and getAll Users then configure the Dockerfile and then docker-compose.yml. once I run docker-compose up, its starts creating images and containers and I can see that they are running perfectly ( the status is running ) but they are not creating user tables in MySQL or in simple it is not running the Springboot application just running dockerfile and docker-compose.yml..
Dockerfile
FROM openjdk:21
LABEL authors="MohammedKhadeer"
WORKDIR /usr/src/myapp
COPY . /usr/src/myapp/
#ENTRYPOINT ["java", "-jar","./target/docker-0.0.1-SNAPSHOT.jar"]
CMD ["java", "-jar","./target/docker-0.0.1-SNAPSHOT.jar"]
docker-compose.yml
services:
mydb:
image: mysql:latest
container_name: mysql_database_latest
environment:
- MYSQL_DATABASE = docker-testing
- MYSQL_USER = admin
- MYSQL_PASSWORD = root
- MYSQL_ROOT_PASSWORD = root
restart: unless-stopped
volumes:
- ./data:/var/lib/mysql
ports:
- 3333:3306
networks:
- myapplication
myapp:
build: ./docker
container_name: docker_boot_app
depends_on:
- mydb
environment:
- spring.datasource.url=jdbc:mysql://mydb:3306/docker-testing?createDatabaseIfNotExist=true
- spring.datasource.username=admin
- spring.datasource.password=root
ports:
- 8081:8080
networks:
- myapplication
networks:
myapplication:
application.property
spring.application.name=docker
#spring.datasource.url=jdbc:mysql://localhost:3306/docker-testing
#spring.datasource.username=admin
#spring.datasource.password=root
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true