Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez javiergs@calpoly.edu www.javiergs.info o ffi ce: 14 -227 CSC 508/9 Software Engineering (Design & Deployment) Lecture 12. Docker

Slide 2

Slide 2 text

Deployment 2

Slide 3

Slide 3 text

Container 3

Slide 4

Slide 4 text

Docker 4

Slide 5

Slide 5 text

It is not VM • Containers share the host operating system kernel, libraries, and binaries. • Virtual machines run its own guest operating system, • Virtual machines provide full-blown virtualization of hardware resources, including CPU, memory, storage, and networking. 5

Slide 6

Slide 6 text

Docker | Run 6 Docker Engine

Slide 7

Slide 7 text

Docker | Steps 7 2. A package that includes everything needed to run software, including the code, runtime, libraries, dependencies, and configuration files. 3. A container is a runtime instance of an image. It encapsulates the execution environment for a specific application or process, including the filesystem, environment variables, network settings, and runtime options. 1. A text file that contains instructions for building a Docker image

Slide 8

Slide 8 text

UR e-Series Control Panel 8

Slide 9

Slide 9 text

Step 1. Set Up

Slide 10

Slide 10 text

Install Docker Desktop 10

Slide 11

Slide 11 text

Plugin 11

Slide 12

Slide 12 text

Connect with your IDE 12

Slide 13

Slide 13 text

Step 2. Maven Application as Usual

Slide 14

Slide 14 text

Create an Application 14

Slide 15

Slide 15 text

15

Slide 16

Slide 16 text

16

Slide 17

Slide 17 text

17

Slide 18

Slide 18 text

Step 3. Write a Docker f ile

Slide 19

Slide 19 text

Docker f ile 19 https:/ /docs.docker.com/reference/dockerfile/ FROM openjdk:20-jdk

Slide 20

Slide 20 text

Run/Debug 20

Slide 21

Slide 21 text

Run/Debug 21

Slide 22

Slide 22 text

Run Docker f ile 22

Slide 23

Slide 23 text

Docker Desktop 23

Slide 24

Slide 24 text

Test Yourselves

Slide 25

Slide 25 text

Docker f ile FROM ubuntu:20.04 # Install Java RUN apt-get update && apt-get install -y openjdk-20-jdk # Install MySQL RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server # Copy the application JAR file COPY target/your-app.jar /app/your-app.jar # Copy the initialization SQL script COPY init.sql /docker-entrypoint-initdb.d/init.sql # Set the working directory WORKDIR /app # Expose ports EXPOSE 3306 25

Slide 26

Slide 26 text

Docker f ile # Environment variables for MySQL ENV MYSQL_ROOT_PASSWORD=root ENV MYSQL_DATABASE=yourdbname # Start MySQL and the Java application CMD service mysql start && \ sleep 10 && \ mysql -u root -proot yourdbname < /docker-entrypoint-initdb.d/init.sql && \ java -jar /app/your-app.jar 26

Slide 27

Slide 27 text

UR e-Series Control Panel 27

Slide 28

Slide 28 text

Docker f ile 28

Slide 29

Slide 29 text

Docker f ile 29

Slide 30

Slide 30 text

Docker f ile 30

Slide 31

Slide 31 text

Questions 31

Slide 32

Slide 32 text

CSC 509 Software Engineering Javier Gonzalez-Sanchez, Ph.D. javiergs@calpoly.edu Fall 2024 Copyright. These slides can only be used as study material for the class CSC509 at Cal Poly. They cannot be distributed or used for another purpose.