DockerCTSNotes
DockerCTSNotes
Scenario
Objective
Identify the list of software to be installed in the server for deploying spring-learn and angular-
learn application [HINT: development tools should not be installed in the server (example:
Eclipse)]
A group size should be four. If not possible to equally divide, few groups can have size of three.
To randomize the group members, use the online tool available at
https://www.aschool.us/random/random-pair.php
Enter “Max group size” as 4
In the text area after “balance”, copy and paste learners list of the classroom. Each line
should have one name
Click “Submit” which will display the groups and the list of people in each group
Project the screen and show the groups
The group leader has to convey the team name and the software list to the SME
SME has to write the group name and the software list on the board under the respective team
name
Once all the teams had provided the details, the SME has to brainstorm and finalize the list of
software required.
List out the components for deploying angular-learn and spring-learn application with eureka
discovery and zuul gateway
For each component list out the steps required for deployment
With the assumption that your PC has only the list of software identified in the previous activity
The list of steps should only use the software identified and should not use any development
tools
Continue working as same groups formed in the previous activity
The group lead of each team has to collect inputs from each team member, debate and arrive at
the final list
Component 1
o Deployment step 1
o Deployment step 2
Component 2
o Deployment step 1
o Deployment step 2
o Deployment step 3
Component 3
o Deployment step 1
Activity Finalization
How much time is required to deploy our application in the remote server?
Is it possible to automate deployment steps? (Find available tools by searching internet with
keywords "deployment automation tools")
In the remote server, JRE 11 is already installed and is used by an application. Our application is
tested in JRE 8 and not tested in JRE 11. How do we address this issue? (Containerization
addresses this issue, learn and find out various tools available by using the search keyword
"container deployment tools")
What is Docker?
Let us do a simple exercise before trying to understand Docker and it's benefits.
Execute the following commands. The explanation for these statements will be provided later:
docker image ls
docker container ls -a
This command downloads linux debian operating system from docker hub
(https://hub.docker.com/) and runs linux operating system within the local docker server.
A linux operating system command prompt opens up and should look something similar to this:
root@86bdf44d1bd7:/#
pwd
ls
uname -a
exit
Demonstrate hosting a web application in nginx using command line and Dockerfile
o nginx, pull, run, listing images, container name, detaching the process, port number, volumes, listing containers,
listing non running containers, starting and stoping a container, Dockerfile, FROM, COPY, ENTRYPOINT, build,
remove images and containers
Nginx Reference - https://hub.docker.com/_/nginx
Docker CLI - https://docs.docker.com/engine/reference/commandline/cli/
Create an Hello World html page and host it in the nginx docker container.
docker image ls
Execute the following command to run the nginx container from the nginx image. [NOTE: This
command can be directly executed without executing the pull command. If the image is not
available, the run command itself will download it and then run the container]
docker container ls
Test the execution of the nginx server by opening http://locahost:8085 in the browser
Command to stop the server
docker stop my-nginx
Now issue the below command will not display the container. As this command does not list
stopped container
docker container ls
docker container ls -a
FROM nginx:1.17.5
COPY home.html /usr/share/nginx/html
docker build .
The above command uses the options specified in Dockerfile and runs the container
Check if the application runs using browser
Use 'docker image ls', 'docker container ls' and 'docker container ls -a' to view the list of existing
images and containers
Use 'docker image rm [IMAGE_ID]' and 'docker container rm [CONTAINER_ID]' to remove an
image. IMAGE_ID And CONTAINER_ID can be obtained using the ls command
Start mysql in a container with necessary schema, table and data available
Deploy authentication microservice REST API and link this service with mysql container.
Deploy application microservice REST API in a container that addresses the business logic of the
application
Deploy eureka discovery service in a container
Deploy zuul gateway service that acts as a gateway for authentication and application
microservices
Deploy angular application in nginx
Test if the application works end to end
Organize Folder
Create a new folder named docker-build in C:\Users\[EMP_ID] folder. This will be the root folder
for all the components that we are going to dockerize.
Copy all project folders in this new folder. The list of projects are provided below for quick
reference:
o dbscript - This folder should contain the schema creation script for 'ormlearn' database
o authentication-service - This is the microservice project split from spring-learn that
authenticates and generates JWT
o employee-service - This is the microservice project split from spring-learn that handles
services related to employee
o eureka-discovery-service - Service Registry
o zuul-gateway-service - Gateway Service for authentication-service and employee-service
o angular-learn - This folder has to contain the angular project
Refer steps specified in the subsequent exercises to incorporate the above deployment.
Containerize MySQL
Steps to setup MySQL container
version: '3'
services:
payroll-mysql:
image: mysql:8.0.18
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
volumes:
- d:/payrolldb:/var/lib/mysql
- ./dbscripts:/docker-entrypoint-initdb.d
docker-compose up
If the start up of MySQL server fails with port conflict error, please follow the steps below to stop
MySQL server running in the desktop PC
o Open Task Manager
o Click Services
o Find item in the list that starts as “MySQL”
o Right click on the item and select stop (later if MySQL needs to be started, come back to
Task Manager and start it)
o Run docker compose
This will start the MySQL server in container
Open another command prompt and execute the below command to execute mysql client and
check if the database is created and tables are populated with necessary data.
This above command will open linux bash command prompt. Execute the following command to
login into the mysql running in the container:
mysql -u root -p
After login check if the schema is created and tables with data is present
Create a file named 'Dockerfile' in the authentication-service folder with the below specified
content
FROM openjdk:8-jdk-alpine
COPY target/authentication-service-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom -Djava.net.preferIPv4Stack=true","-jar","/
app.jar"]
Explanation for the Dockerfile configuration
o FROM command pulls JDK 8 from docker hub
o COPY command copies the jar created in target folder to the project root folder with
name app.jar
o ENTRYPOINT execute the java command and starts the REST API Service
Modify docker-build\docker-compose.yml so that the entire file content looks like the one below.
Ideally authentication-service had been added in the file:
version: '3'
services:
payroll-mysql:
image: mysql:8.0.18
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
volumes:
- d:/payrolldb:/var/lib/mysql
- ./dbscripts:/docker-entrypoint-initdb.d
authentication-service:
image: authentication-app
build: authentication-service/.
ports:
- 8091:8091
depends_on:
- payroll-mysql
links:
- payroll-mysql
spring.datasource.url=jdbc:mysql://payroll-mysql:3306/ormlearn?allowPublicKeyRetrieval=true&useSSL=false
Execute maven build in command line on authentication-service folder to create jar file with
updated configuration
Execute 'docker-compose up' command in docker-build folder. This will start mysql server and
authentication-service
Test the http://localhost:8090/authenticate REST API using Postman or curl command and verify
if the service works end to end and returns back the token.
employee-service
o Create a Dockerfile similar to the one done for authorisation-service
o Modify port as 8092 and mysql connection URL in application.properties
o Modify docker-compose.yml with inclusion of employee-service linking to payroll-mysql
o Run docker compose and test a REST API service in employee-service to verify if the
service works end to end
eureka-discovery-service
o Create a Dockerfile similar to the one done for authorisation-service
o Modify port as 8093 and mysql connection URL in application.properties
o Run docker compose and test if the registry service gets hosted
zuul-gateway-service
o Create a Dockerfile similar to the one done for authorisation-service
o Modify port as 8094
o Modify docker-compose.yml with inclusion of zuul-gateway-service linking to
authentication-service and employee-service
o Run docker compose and test a REST API service in authentication-service and
employee-service to verify if the service works end to end
angular-learn
o Modify the REST API URL in the angular application refering to zuul-gateway-service
o Execute the angular build which creates the dist folder
o Create a Dockerfile that copies dist folder content to nginx container and starts the server
(Reference: https://hub.docker.com/_/nginx)
o Include docker-compose.yml with a new service named angular-service that runs the
Dockerfile and links with zuul-gateway-service
o Run docoker compose and test the angular application to see if it works end to end