A simple docker example using springboot and database as mysql/mariadb
Create springboot image
Get the completed springboot source code on github for hello-docker imageRun individual container(s) in a docker network
Since springboot application need to connect to database, both the containers should be present in same docker network.
1. Created docker network
docker network create mynetwork
2. Run database image in docker network
docker run -d --name mysqldb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=pass123 -e MYSQL_DATABASE=mydb --network mynetwork mysql
3. Run springboot application
docker run -d --name hello-docker -p 8080:8080 -e SPRING_DATASOURCE_URL="jdbc:mysql://mysqldb:3306/mydb?useSSL=false" -e SPRING_DATASOURCE_USERNAME=root -e SPRING_DATASOURCE_PASSWORD=pass123 --network mynetwork madan712/hello-docker:v1.0
Run multi-container docker application using docker compose
docker-compose.yaml
Compose command
docker-compose up -d
Please find complete github code - hello-docker