0% found this document useful (0 votes)
3 views

Dockerize Spring Boot With MySQL

The document provides a step-by-step guide for dockerizing a Spring Boot application with a MySQL database. It includes commands for pulling the MySQL image, cloning the Spring Boot project, building the application, creating a Docker network, and running both the MySQL and Spring Boot containers. The final instructions detail how to access the application via a public URL.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Dockerize Spring Boot With MySQL

The document provides a step-by-step guide for dockerizing a Spring Boot application with a MySQL database. It includes commands for pulling the MySQL image, cloning the Spring Boot project, building the application, creating a Docker network, and running both the MySQL and Spring Boot containers. The final instructions detail how to access the application via a public URL.

Uploaded by

Suresh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4/29/23, 3:23 PM https://ashokitech.com/uploads/notes/33447707_1664730157.

txt

===================================
Dockerizing Spring Boot + MySQL
===================================

# Pull MySQL DB image


$ docker pull mysql:5.7

# Download required softwares


$ sudo yum install git -y
$ sudo yum install maven -y

# Clone Spring Boot Project From Github


$ git clone https://github.com/ashokitschool/spring-boot-mysql-docker-compose.git

# Get into project directory


$ cd <project-dir>

# Package application
$ mvn clean package

# Create Application image


$ docker build -t sb-app .

# Check docker images


$ docker images

# Create Docker Network


$ docker network create springmysql-net

# See networks available


$ docker network ls

# Run mysqldb as a docker container


$ docker run --name mysqldb --network springmysql-net -e MYSQL_ROOT_PASSWORD=root -e
MYSQL_DATABASE=sbms -d mysql:5.7

# check logs of container


$ docker logs -f <container_name>

If needed we can check if the database has been created correctly.

We can do the following commands.

$ docker exec -it <container_id> bash


$ mysql -u <username> -p
$ show databases;

# Run springboot application as a container


$ docker run --network springmysql-net --name sbapp-container -p 8080:8080 -d sb-app

# check the containers which are running


$ docker ps

# check logs of application container


$ docker logs -f <container_id>

# We can access our application now

URL : http://ec2-vm-public-ip:8080/

https://ashokitech.com/uploads/notes/33447707_1664730157.txt 1/2
4/29/23, 3:23 PM https://ashokitech.com/uploads/notes/33447707_1664730157.txt

https://ashokitech.com/uploads/notes/33447707_1664730157.txt 2/2

You might also like