Containerizing a Web Application with Vue.js and Java

Jadson Santos
Jadson SantosAnalista de TI à SINFO - Superintendência de Informática da UFRN
Jadson Santos
Containerizing a Web Application with Vue.js and
Java
Container
• Seaports before container were a mess
27/09/2021 Docker 2
Container
• After container, load a ship became faster
27/09/2021 Docker 3
Container
• How setup the execution environment
• 1o Install directly in SO: Very complex, several different configurations
• 2o Use virtual machines like VMWare, Virtual Box: memory and processing
consumption is too high
• 3o Use a container: it's possible to run an application with all the required
settings (environment variables, packages, etc.) with minimal impact
27/09/2021 Docker 4
Container
• Containers isolate microservice processes and applications into smaller
instances that utilize only the virtualized operating system rather than the
full virtual machine and the entire complement of abstracted hardware that
VM includes
• For containers, they operate more as fully isolated sandboxes, with only the
minimal kernel of the operating system present for each container.
27/09/2021 Docker 5
Container
27/09/2021 Docker 6
Installation
27/09/2021 Docker 7
Docker
• Docker is a set of platform-as-a-service products that use operating system-
level virtualization to deliver software in packages called containers.
• Docker do not create the container technology, but was the first tool to let is
popular and and relatively easy to use.
27/09/2021 Docker 8
Registry
Docker Daemon
Containers Images
Client
docker run
docker build
docker pull
Docker
• Client: Client receiving and executes the commands of users
• Docker Daemon: Who manages the containers
• Registry: Where the images are stored
27/09/2021 Docker 9
Installation
• Linux
• First, install some prerequisite packages that let apt use packages over HTTPS:
• sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-
properties-common
• Add the GPG key to the official Docker repository on your system:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add
-
• Add the Docker repository to the APT sources:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu
focal stable"
27/09/2021 Docker 10
Installation
• Linux
• Then update the database with the Docker packages from the newly added repository:
• sudo apt update
• Now, install the Docker
• sudo apt install docker-ce
• Add your username to the docker group:
• sudo usermod -aG docker “user”
27/09/2021 Docker 11
Installation
• Mac OS
• Go to https://hub.docker.com/
• Download Docker Desktop for Mac
• Docker is native for Linux, to run on Windows and MacOS we need the Docker Desktop
27/09/2021 Docker 12
Installation
• Mac OS
• Type docker version
27/09/2021 Docker 13
Docker Introduction
• Hello World
docker container run hello-world
27/09/2021 Docker 14
image name
Docker Introduction
• Hello World
• There is an image “hello-world” locally?
27/09/2021 Docker 15
Registry
Docker Daemon
Containers Images
Client
docker run
Docker Introduction
• Hello World
• Download from registry (https://hub.docker.com/)
27/09/2021 Docker 16
Registry
Docker Daemon
Containers Images
Client
docker run
Docker Introduction
• Hello World
• Run the container that is an instance of “hello-world” image
27/09/2021 Docker 17
Registry
Docker Daemon
Containers Images
Client
docker run
Docker Introduction
• Docker hub
• Docker hub is the default docker registry
• It has unlimited public repositories
27/09/2021 Docker 18
Docker Introduction
• Docker hub
• You can search for images
• Give preference to official
images
27/09/2021 Docker 19
Docker Introduction
• Docker hub
• Each image has several tags
• Choose the image that best fits your application requirements
27/09/2021 Docker 20
Docker Introduction
• Docker hub
• You can install local registry to your company.
27/09/2021 Docker 21
Docker Introduction
• List the containers running
• docker container ls
• List all containers
• docker container ls -a
27/09/2021 Docker 22
Docker Introduction
• Give a name to the container
• docker container run -–name my_hello_container hello-world
27/09/2021 Docker 23
Docker Introduction
• Removing a container
• docker container rm <ID or NAME>
• Restarting the container
• docker container restart <ID or NAME>
• Stopping the container
• docker container stop <ID or NAME>
27/09/2021 Docker 24
Docker Introduction
• Accessing the container
• Download the “ubuntu” image, run the container using this image and give me access the
/bin/bash application inside de container
• docker container run -it ubuntu /bin/bash
• Accessing the container when it is running
• docker container exec -it ubuntu /bin/bash
27/09/2021 Docker 25
In this case, the application argument
stay after image name, in the other
cases, image name is always the last
argument of command
Docker Port Binding
• To have access an application running inside the container, it is necessary to
define a port from the port bind. In the format HOST : CONTAINER
• docker container run -p 27017:27017 mongo
27/09/2021 Docker 26
Bing the mongo DB 27017 port (mongo db goes up
inside de container) to the 27017 HOST port
HOST : Mongo DB
Docker Images
• Docker images act as a template to build a Docker container.
• Docker images contains layers that install libraries, tools, dependences, files needed to
make your application run.
• Docker images layers increase reusability, decrease disk usage, and speed up docker
build by allowing each step to be cached.
• We need to create an image containing our application to run it on a Docker
27/09/2021 Docker 27
Image
Layer 01
Layer 02
Layer 03
Layer 04
Layer N
Docker Images
• The easiest way to create an image is via the Dockerfile file
• Example of Dockerfile of a simple Node application
27/09/2021 Docker 28
Docker Images
• The easiest way to create an image is via the Dockerfile file
• Example of Dockerfile of a simple Node application
27/09/2021 Docker 29
Docker Images
• The easiest way to create an image is via the Dockerfile file
• Starting downloading a node image
• Create a working directory (WORKDIR == “mkdir /app” and “cd /app”)
• Copies the .package.json and .package-lock.json file
• Run “npm install” to download and install node dependencies
• Copy the other files of project
• When the container goes up, execute the command “node app.js"
27/09/2021 Docker 30
Docker Images
• Build a image with your node application
• docker build . -t jadsonjs/appnode:v1
27/09/2021 Docker 31
Image name
(name space + repository + tag)
Docker Images
• List the images
docker image ls
27/09/2021 Docker 32
Docker Images
• Execute your node application inside the docker
docker container run –d –p 8080:8081 -–name my_appnode_container jadsonjs/appnode:v1
docker container ls
27/09/2021 Docker 33
Image name
Container name
Run in background
Bind the 8081 NODE application port to 8080 HOST port
Docker Images
• Execute your node application inside the docker
27/09/2021 Docker 34
Docker Images
• Publish image to docker hub
• Publish the image to my account do docker hub as a public image that other people can
use.
docker login
docker push jadsonjs/appnode:v1
27/09/2021 Docker 35
Docker Images
• Publish image to docker hub
• Publish the image to my account do docker hub as a public image that other people can
use.
27/09/2021 Docker 36
Docker Networks
• If you are going to run 2 or more applications in 2 or more separate containers
and need them to communicate. Must create a network between these
containers
docker network create my-app-net
docker container run -–name api –d -p 8080:8080 -–network=my-app-net
jadsonjs/appnode:v1
docker container run -–name mongodb -d -p 27017:27017 -e USER=user -e
PASS=1234 -–network=my-app-net mongo:5.0.3
27/09/2021 Docker 37
Docker Volumes
• Used to save data if you kill and upload the container again. Example:
Container of a database.
• Link container file system with the host file system
• This can be done via directory bind. In the format HOST : CONTAINER, similar with port
bind
docker container run -–name bancoDeDadosMongo -d -p 27017:27017 -e
USER=user -e PASS=1234 -–network=api-net -v “/usr/local/mongodb:/data/db”
mongo:5.0.3
27/09/2021 Docker 38
Bind the /data/db mongo db directory with /usr/local/mongodb HOST directory
In other words, the data will be save in /usr/local/mongodb HOST directory
Docker Volumes
• Creating a volume
docker volume create mongodb_vol
docker container run -–name mongodb -d -p 27017:27017 -e USER=user -e
PASS=1234 -–network=my-app-net -v “mongodb_vol:/data/db” mongo:5.0.3
27/09/2021 Docker 39
Bind the /data/db mongo db directory with a mongodb_vol create by the container
mongodb_vol is a directory in HOST machine created and managed by container
Docker Volumes
• Creating a volume
docker volume ls
docker volume inspect mongo_db_vol
27/09/2021 Docker 40
Vue JS Application on Docker
27/09/2021 Docker 41
Vue JS Application on Docker
• Let’s create a simple VUE calculator
application with de command
• vue create calculator-front-end
• The application will be a simple calculator that
will call a back-end application written in Java.
• The front end application will be deployed
using nginx server.
• The back end application will be deployed in
another Docker container.
27/09/2021 Docker 42
Vue JS Application on Docker
• Let’s create a simple VUE calculator application
• We create a nginx.conf file in the project root that configure your “calculator” application
• When somebody type “/calculator” on url, the nginx serve should execute the /calculator/index.html of a
VUE Single Page Application project
• This file will be copy into the container file system.
27/09/2021 Docker 43
Vue JS Application on Docker
• Let’s create a simple VUE calculator application
• For the vue app work inside nginx server, we have to define a context to VUE application when
execute on Docker, we make this in the vue.config.js file.
27/09/2021 Docker 44
Vue JS Application on Docker
• In the dockerfile file, we define some
steps to build our image
• Build Steps:
• Download a “node” image
• Create a temp directory “app” and copy
package*.json files to it
• Install all Vue dependences
• Copy the other files and make the build of
project
• Execution Steps:
• Now, download a image of nginx
• Copy the vue “dist” directory content to nginx
default directory: /usr/share/nginx renaming it.
• And copy the nginx.conf file (in the root of the
project) to nginx default configuration directory:
/etc/nginx/
27/09/2021 Docker 45
Vue JS Application on Docker
• Now, we need to build the image
• docker build . -t calculator-front-end
• After that, we create a network and run the docker container
• This same network will be used by the back end container
• docker network create calculator-net
• docker run -d -p 8080:8080 –network=calculator-net calculator-front-end
27/09/2021 Docker 46
Vue JS Application on Docker
• When the container goes up, the ningx server will goes up also and make
deploy of our application following the nginx.conf files
• We can access the application on address: http://localhost:8080/calculator/
27/09/2021 Docker 47
Java Application on Docker
27/09/2021 Docker 48
Java Application on Docker
• We will create a simple Java spring boot back-end application for our
calculator
• We will use Gradle as a build tool.
27/09/2021 Docker 49
Java Application on Docker
• Now we will configure dockerfile file
to create a docker image
• Build Steps:
• Download the gradle image
• Create a workdir
• Copy all files to this workdir
• Run the gradle build
• Executions steps:
• Download JDK 11 image
• Copy and rename the application jar
• Expose the back end port
• Execute the Java application when
container goes up
27/09/2021 Docker 50
Java Application on Docker
• We can build the Java back end image with this command
• docker build . -t calculator-back-end
27/09/2021 Docker 51
Java Application on Docker
• Now we can run the back end Java application with this command
• PS.: The front end application should be already running (previous slides)
• docker run -d -p 8081:8081 –network=calculator-net calculator-back-end
27/09/2021 Docker 52
Java Application on Docker
• If everything was ok, now we have a front end VUE.js application run with
nginx server on a Docker calling a back end Java application run on Docker
also.
27/09/2021 Docker 53
Source Code
• https://github.com/jadsonjs/containers
27/09/2021 Docker 54
27/09/2021 Docker 55
Docker Compose
• Docker Compose is a tool for defining
and running multi-container Docker
applications. With Compose, you can
use a YAML file to configure and start
several docker applications.
• So, create a docker-compose.yaml
file with the follow content
27/09/2021 Docker 56
Docker Compose
• First we define the version and the networks of our containers
• We define a new network to the docker compose create it
27/09/2021 Docker 57
Docker Compose
• Now, we need to define our services (containers)
• The first one is the VUE js front end application.
• It uses the calculator-front-end image in port 8080:8080, using the calculator-net2
network and should starts after back-end container
27/09/2021 Docker 58
Docker Compose
• Now, we need to define our services (containers)
• The second one is the Java back end application.
• It uses the calculator-back-end image in port 8081:8081, using the same calculator-
net2 network.
27/09/2021 Docker 59
Docker Compose
• Now, just execute the follow command:
• docker compose up -d
• This command will replace the follow two commands and simplify the
docker execution
• docker run -d -p 8080:8080 –network=calculator-net calculator-front-end
• docker run -d -p 8081:8081 –network=calculator-net calculator-back-end
• To stop the execution of containers, type:
• docker compose down
27/09/2021 Docker 60
References
• https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-
ubuntu-20-04
• https://cli.vuejs.org/guide/deployment.html#docker-nginx
• https://medium.com/bb-tutorials-and-thoughts/how-to-serve-vue-js-application-with-nginx-
and-docker-d8a872a02ea8
•
https://www.baeldung.com/dockerizing-spring-boot-application
• https://docs.docker.com/language/java/build-images/
27/09/2021 Docker 63
References
• https://medium.com/swlh/spring-boot-with-docker-2467db187fa2
• https://dzone.com/articles/docker-with-spring-boot-how-to
• https://docs.docker.com/compose/
27/09/2021 Docker 64
27/09/2021 Docker 65
1 sur 63

Recommandé

Micro services and Containers par
Micro services and ContainersMicro services and Containers
Micro services and ContainersRichard Harvey
4.2K vues12 diapositives
Azure Service Fabric 概要 par
Azure Service Fabric 概要Azure Service Fabric 概要
Azure Service Fabric 概要Daiyu Hatakeyama
3.9K vues70 diapositives
Docker 101: Introduction to Docker par
Docker 101: Introduction to DockerDocker 101: Introduction to Docker
Docker 101: Introduction to DockerDocker, Inc.
71.2K vues30 diapositives
infrastructure as code par
infrastructure as codeinfrastructure as code
infrastructure as codeAmazon Web Services
4.3K vues72 diapositives
Introduction to docker par
Introduction to dockerIntroduction to docker
Introduction to dockerFrederik Mogensen
2.4K vues39 diapositives
オフラインWebアプリケーションのつくりかた par
オフラインWebアプリケーションのつくりかたオフラインWebアプリケーションのつくりかた
オフラインWebアプリケーションのつくりかたShumpei Shiraishi
9.4K vues36 diapositives

Contenu connexe

Tendances

Container orchestration overview par
Container orchestration overviewContainer orchestration overview
Container orchestration overviewWyn B. Van Devanter
1.1K vues44 diapositives
DevOps with Database on AWS par
DevOps with Database on AWSDevOps with Database on AWS
DevOps with Database on AWSAmazon Web Services Japan
40.3K vues47 diapositives
Alphorm.com Formation Microsoft Azure (AZ-900) : Les Fondamentaux par
Alphorm.com Formation Microsoft Azure (AZ-900) : Les FondamentauxAlphorm.com Formation Microsoft Azure (AZ-900) : Les Fondamentaux
Alphorm.com Formation Microsoft Azure (AZ-900) : Les FondamentauxAlphorm
27.6K vues276 diapositives
msal.js v2を触る par
msal.js v2を触るmsal.js v2を触る
msal.js v2を触るDevTakas
597 vues27 diapositives
Azure Introduction par
Azure IntroductionAzure Introduction
Azure Introductionbrunoterkaly
1.4K vues40 diapositives
Azure Key Vault par
Azure Key VaultAzure Key Vault
Azure Key Vaultjunichi anno
3.3K vues42 diapositives

Tendances(20)

Alphorm.com Formation Microsoft Azure (AZ-900) : Les Fondamentaux par Alphorm
Alphorm.com Formation Microsoft Azure (AZ-900) : Les FondamentauxAlphorm.com Formation Microsoft Azure (AZ-900) : Les Fondamentaux
Alphorm.com Formation Microsoft Azure (AZ-900) : Les Fondamentaux
Alphorm27.6K vues
msal.js v2を触る par DevTakas
msal.js v2を触るmsal.js v2を触る
msal.js v2を触る
DevTakas 597 vues
DynamoDBによるソーシャルゲーム実装 How To par 伊藤 祐策
DynamoDBによるソーシャルゲーム実装 How ToDynamoDBによるソーシャルゲーム実装 How To
DynamoDBによるソーシャルゲーム実装 How To
伊藤 祐策36.6K vues
Spring Bootハンズオン ~Spring Bootで作る マイクロサービスアーキテクチャ! #jjug_ccc #ccc_r53 par Toshiaki Maki
Spring Bootハンズオン ~Spring Bootで作る マイクロサービスアーキテクチャ! #jjug_ccc #ccc_r53Spring Bootハンズオン ~Spring Bootで作る マイクロサービスアーキテクチャ! #jjug_ccc #ccc_r53
Spring Bootハンズオン ~Spring Bootで作る マイクロサービスアーキテクチャ! #jjug_ccc #ccc_r53
Toshiaki Maki36.1K vues
はじめてのAzure Web App for Containers! -コンテナの基礎から DevOps 環境の構築まで- par Saki Homma
はじめてのAzure Web App for Containers! -コンテナの基礎から DevOps 環境の構築まで-はじめてのAzure Web App for Containers! -コンテナの基礎から DevOps 環境の構築まで-
はじめてのAzure Web App for Containers! -コンテナの基礎から DevOps 環境の構築まで-
Saki Homma3.3K vues
Azure Monitor Logで実現するモダンな管理手法 par Takeshi Fukuhara
Azure Monitor Logで実現するモダンな管理手法Azure Monitor Logで実現するモダンな管理手法
Azure Monitor Logで実現するモダンな管理手法
Takeshi Fukuhara3.7K vues
「DevSecOpsとは?」の一歩先 (CloudNative Days Tokyo 2021) par Masaya Tahara
「DevSecOpsとは?」の一歩先 (CloudNative Days Tokyo 2021)「DevSecOpsとは?」の一歩先 (CloudNative Days Tokyo 2021)
「DevSecOpsとは?」の一歩先 (CloudNative Days Tokyo 2021)
Masaya Tahara441 vues
IDaaS を正しく活用するための認証基盤設計 ~Azure Active Directory の構成パターン詳細~ par Trainocate Japan, Ltd.
IDaaS を正しく活用するための認証基盤設計 ~Azure Active Directory の構成パターン詳細~IDaaS を正しく活用するための認証基盤設計 ~Azure Active Directory の構成パターン詳細~
IDaaS を正しく活用するための認証基盤設計 ~Azure Active Directory の構成パターン詳細~
Notes/Domino アプリがそのまま Web ブラウザで動く HCL Nomad Web の簡単な導入と「仕掛け」 par Software Info HCL Japan
Notes/Domino アプリがそのまま Web ブラウザで動く HCL Nomad Web の簡単な導入と「仕掛け」Notes/Domino アプリがそのまま Web ブラウザで動く HCL Nomad Web の簡単な導入と「仕掛け」
Notes/Domino アプリがそのまま Web ブラウザで動く HCL Nomad Web の簡単な導入と「仕掛け」
Docker introduction par dotCloud
Docker introductionDocker introduction
Docker introduction
dotCloud455.8K vues
Azure Functions&Logic Appではじめるサーバレスアプリケーション開発 - 入門編 - par Yoichi Kawasaki
Azure Functions&Logic Appではじめるサーバレスアプリケーション開発 - 入門編 -Azure Functions&Logic Appではじめるサーバレスアプリケーション開発 - 入門編 -
Azure Functions&Logic Appではじめるサーバレスアプリケーション開発 - 入門編 -
Yoichi Kawasaki1.9K vues
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料) par NTT DATA Technology & Innovation
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
オススメのJavaログ管理手法 ~コンテナ編~(Open Source Conference 2022 Online/Spring 発表資料)
KubernetesでRedisを使うときの選択肢 par Naoyuki Yamada
KubernetesでRedisを使うときの選択肢KubernetesでRedisを使うときの選択肢
KubernetesでRedisを使うときの選択肢
Naoyuki Yamada4.8K vues

Similaire à Containerizing a Web Application with Vue.js and Java

Docker and Microservice par
Docker and MicroserviceDocker and Microservice
Docker and MicroserviceSamuel Chow
1.1K vues46 diapositives
Docker Kubernetes Istio par
Docker Kubernetes IstioDocker Kubernetes Istio
Docker Kubernetes IstioAraf Karsh Hamid
3.7K vues129 diapositives
Docker slides par
Docker slidesDocker slides
Docker slidesJyotsna Raghuraman
9.1K vues22 diapositives
Docker From Scratch par
Docker From ScratchDocker From Scratch
Docker From ScratchGiacomo Vacca
15.4K vues44 diapositives
Up and running with docker par
Up and running with dockerUp and running with docker
Up and running with dockerMichelle Liu
638 vues54 diapositives
IBM WebSphere Application Server traditional and Docker par
IBM WebSphere Application Server traditional and DockerIBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and DockerDavid Currie
10.3K vues39 diapositives

Similaire à Containerizing a Web Application with Vue.js and Java(20)

Docker and Microservice par Samuel Chow
Docker and MicroserviceDocker and Microservice
Docker and Microservice
Samuel Chow1.1K vues
Up and running with docker par Michelle Liu
Up and running with dockerUp and running with docker
Up and running with docker
Michelle Liu638 vues
IBM WebSphere Application Server traditional and Docker par David Currie
IBM WebSphere Application Server traditional and DockerIBM WebSphere Application Server traditional and Docker
IBM WebSphere Application Server traditional and Docker
David Currie10.3K vues
Docker: From Zero to Hero par fazalraja
Docker: From Zero to HeroDocker: From Zero to Hero
Docker: From Zero to Hero
fazalraja1.9K vues
[@NaukriEngineering] Docker 101 par Naukri.com
[@NaukriEngineering] Docker 101[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101
Naukri.com317 vues
Introduction to Docker Containers - Docker Captain par Ajeet Singh Raina
Introduction to Docker Containers - Docker CaptainIntroduction to Docker Containers - Docker Captain
Introduction to Docker Containers - Docker Captain
Ajeet Singh Raina3.8K vues
Virtualization, Containers, Docker and scalable container management services par abhishek chawla
Virtualization, Containers, Docker and scalable container management servicesVirtualization, Containers, Docker and scalable container management services
Virtualization, Containers, Docker and scalable container management services
abhishek chawla2.3K vues
Docker fundamentals par Alper Unal
Docker fundamentalsDocker fundamentals
Docker fundamentals
Alper Unal663 vues

Plus de Jadson Santos

Continuous Delivery with Jenkins par
Continuous Delivery with JenkinsContinuous Delivery with Jenkins
Continuous Delivery with JenkinsJadson Santos
381 vues98 diapositives
Cd with Github Travis CI and Heroku par
Cd with Github Travis CI and HerokuCd with Github Travis CI and Heroku
Cd with Github Travis CI and HerokuJadson Santos
304 vues22 diapositives
Vue.js par
Vue.jsVue.js
Vue.jsJadson Santos
10.7K vues94 diapositives
Jenkins Continuous Delivery par
Jenkins Continuous DeliveryJenkins Continuous Delivery
Jenkins Continuous DeliveryJadson Santos
285 vues47 diapositives
Introduction to angular with a simple but complete project par
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
12.9K vues106 diapositives
Hazelcast Distributed Lock par
Hazelcast Distributed LockHazelcast Distributed Lock
Hazelcast Distributed LockJadson Santos
3.2K vues16 diapositives

Plus de Jadson Santos(18)

Continuous Delivery with Jenkins par Jadson Santos
Continuous Delivery with JenkinsContinuous Delivery with Jenkins
Continuous Delivery with Jenkins
Jadson Santos381 vues
Cd with Github Travis CI and Heroku par Jadson Santos
Cd with Github Travis CI and HerokuCd with Github Travis CI and Heroku
Cd with Github Travis CI and Heroku
Jadson Santos304 vues
Introduction to angular with a simple but complete project par Jadson Santos
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
Jadson Santos12.9K vues
Hazelcast Distributed Lock par Jadson Santos
Hazelcast Distributed LockHazelcast Distributed Lock
Hazelcast Distributed Lock
Jadson Santos3.2K vues
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse - I... par Jadson Santos
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse  -  I...Mini curso gerenciamento de configuração e mudança com GIT + Eclipse  -  I...
Mini curso gerenciamento de configuração e mudança com GIT + Eclipse - I...
Jadson Santos636 vues
Usando hiberante de forma otimizada par Jadson Santos
Usando hiberante de forma otimizadaUsando hiberante de forma otimizada
Usando hiberante de forma otimizada
Jadson Santos572 vues
Usando JMeter para testar sua aplicação JSF par Jadson Santos
Usando JMeter para testar sua aplicação JSFUsando JMeter para testar sua aplicação JSF
Usando JMeter para testar sua aplicação JSF
Jadson Santos3.9K vues
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari... par Jadson Santos
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Conditional Execution - A Pattern for the Implementation of Fine-Grained Vari...
Jadson Santos1.6K vues

Dernier

ADDO_2022_CICID_Tom_Halpin.pdf par
ADDO_2022_CICID_Tom_Halpin.pdfADDO_2022_CICID_Tom_Halpin.pdf
ADDO_2022_CICID_Tom_Halpin.pdfTomHalpin9
5 vues33 diapositives
Page Object Model par
Page Object ModelPage Object Model
Page Object Modelartembondar5
6 vues5 diapositives
The Path to DevOps par
The Path to DevOpsThe Path to DevOps
The Path to DevOpsJohn Valentino
5 vues6 diapositives
predicting-m3-devopsconMunich-2023.pptx par
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptxTier1 app
8 vues24 diapositives
Playwright Retries par
Playwright RetriesPlaywright Retries
Playwright Retriesartembondar5
6 vues1 diapositive
Electronic AWB - Electronic Air Waybill par
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill Freightoscope
5 vues1 diapositive

Dernier(20)

ADDO_2022_CICID_Tom_Halpin.pdf par TomHalpin9
ADDO_2022_CICID_Tom_Halpin.pdfADDO_2022_CICID_Tom_Halpin.pdf
ADDO_2022_CICID_Tom_Halpin.pdf
TomHalpin95 vues
predicting-m3-devopsconMunich-2023.pptx par Tier1 app
predicting-m3-devopsconMunich-2023.pptxpredicting-m3-devopsconMunich-2023.pptx
predicting-m3-devopsconMunich-2023.pptx
Tier1 app8 vues
Electronic AWB - Electronic Air Waybill par Freightoscope
Electronic AWB - Electronic Air Waybill Electronic AWB - Electronic Air Waybill
Electronic AWB - Electronic Air Waybill
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... par NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi216 vues
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... par TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 vues
How Workforce Management Software Empowers SMEs | TraQSuite par TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuiteHow Workforce Management Software Empowers SMEs | TraQSuite
How Workforce Management Software Empowers SMEs | TraQSuite
TraQSuite6 vues
Ports-and-Adapters Architecture for Embedded HMI par Burkhard Stubert
Ports-and-Adapters Architecture for Embedded HMIPorts-and-Adapters Architecture for Embedded HMI
Ports-and-Adapters Architecture for Embedded HMI
aATP - New Correlation Confirmation Feature.pptx par EsatEsenek1
aATP - New Correlation Confirmation Feature.pptxaATP - New Correlation Confirmation Feature.pptx
aATP - New Correlation Confirmation Feature.pptx
EsatEsenek1205 vues

Containerizing a Web Application with Vue.js and Java

  • 1. Jadson Santos Containerizing a Web Application with Vue.js and Java
  • 2. Container • Seaports before container were a mess 27/09/2021 Docker 2
  • 3. Container • After container, load a ship became faster 27/09/2021 Docker 3
  • 4. Container • How setup the execution environment • 1o Install directly in SO: Very complex, several different configurations • 2o Use virtual machines like VMWare, Virtual Box: memory and processing consumption is too high • 3o Use a container: it's possible to run an application with all the required settings (environment variables, packages, etc.) with minimal impact 27/09/2021 Docker 4
  • 5. Container • Containers isolate microservice processes and applications into smaller instances that utilize only the virtualized operating system rather than the full virtual machine and the entire complement of abstracted hardware that VM includes • For containers, they operate more as fully isolated sandboxes, with only the minimal kernel of the operating system present for each container. 27/09/2021 Docker 5
  • 8. Docker • Docker is a set of platform-as-a-service products that use operating system- level virtualization to deliver software in packages called containers. • Docker do not create the container technology, but was the first tool to let is popular and and relatively easy to use. 27/09/2021 Docker 8 Registry Docker Daemon Containers Images Client docker run docker build docker pull
  • 9. Docker • Client: Client receiving and executes the commands of users • Docker Daemon: Who manages the containers • Registry: Where the images are stored 27/09/2021 Docker 9
  • 10. Installation • Linux • First, install some prerequisite packages that let apt use packages over HTTPS: • sudo apt update sudo apt install apt-transport-https ca-certificates curl software- properties-common • Add the GPG key to the official Docker repository on your system: curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - • Add the Docker repository to the APT sources: sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" 27/09/2021 Docker 10
  • 11. Installation • Linux • Then update the database with the Docker packages from the newly added repository: • sudo apt update • Now, install the Docker • sudo apt install docker-ce • Add your username to the docker group: • sudo usermod -aG docker “user” 27/09/2021 Docker 11
  • 12. Installation • Mac OS • Go to https://hub.docker.com/ • Download Docker Desktop for Mac • Docker is native for Linux, to run on Windows and MacOS we need the Docker Desktop 27/09/2021 Docker 12
  • 13. Installation • Mac OS • Type docker version 27/09/2021 Docker 13
  • 14. Docker Introduction • Hello World docker container run hello-world 27/09/2021 Docker 14 image name
  • 15. Docker Introduction • Hello World • There is an image “hello-world” locally? 27/09/2021 Docker 15 Registry Docker Daemon Containers Images Client docker run
  • 16. Docker Introduction • Hello World • Download from registry (https://hub.docker.com/) 27/09/2021 Docker 16 Registry Docker Daemon Containers Images Client docker run
  • 17. Docker Introduction • Hello World • Run the container that is an instance of “hello-world” image 27/09/2021 Docker 17 Registry Docker Daemon Containers Images Client docker run
  • 18. Docker Introduction • Docker hub • Docker hub is the default docker registry • It has unlimited public repositories 27/09/2021 Docker 18
  • 19. Docker Introduction • Docker hub • You can search for images • Give preference to official images 27/09/2021 Docker 19
  • 20. Docker Introduction • Docker hub • Each image has several tags • Choose the image that best fits your application requirements 27/09/2021 Docker 20
  • 21. Docker Introduction • Docker hub • You can install local registry to your company. 27/09/2021 Docker 21
  • 22. Docker Introduction • List the containers running • docker container ls • List all containers • docker container ls -a 27/09/2021 Docker 22
  • 23. Docker Introduction • Give a name to the container • docker container run -–name my_hello_container hello-world 27/09/2021 Docker 23
  • 24. Docker Introduction • Removing a container • docker container rm <ID or NAME> • Restarting the container • docker container restart <ID or NAME> • Stopping the container • docker container stop <ID or NAME> 27/09/2021 Docker 24
  • 25. Docker Introduction • Accessing the container • Download the “ubuntu” image, run the container using this image and give me access the /bin/bash application inside de container • docker container run -it ubuntu /bin/bash • Accessing the container when it is running • docker container exec -it ubuntu /bin/bash 27/09/2021 Docker 25 In this case, the application argument stay after image name, in the other cases, image name is always the last argument of command
  • 26. Docker Port Binding • To have access an application running inside the container, it is necessary to define a port from the port bind. In the format HOST : CONTAINER • docker container run -p 27017:27017 mongo 27/09/2021 Docker 26 Bing the mongo DB 27017 port (mongo db goes up inside de container) to the 27017 HOST port HOST : Mongo DB
  • 27. Docker Images • Docker images act as a template to build a Docker container. • Docker images contains layers that install libraries, tools, dependences, files needed to make your application run. • Docker images layers increase reusability, decrease disk usage, and speed up docker build by allowing each step to be cached. • We need to create an image containing our application to run it on a Docker 27/09/2021 Docker 27 Image Layer 01 Layer 02 Layer 03 Layer 04 Layer N
  • 28. Docker Images • The easiest way to create an image is via the Dockerfile file • Example of Dockerfile of a simple Node application 27/09/2021 Docker 28
  • 29. Docker Images • The easiest way to create an image is via the Dockerfile file • Example of Dockerfile of a simple Node application 27/09/2021 Docker 29
  • 30. Docker Images • The easiest way to create an image is via the Dockerfile file • Starting downloading a node image • Create a working directory (WORKDIR == “mkdir /app” and “cd /app”) • Copies the .package.json and .package-lock.json file • Run “npm install” to download and install node dependencies • Copy the other files of project • When the container goes up, execute the command “node app.js" 27/09/2021 Docker 30
  • 31. Docker Images • Build a image with your node application • docker build . -t jadsonjs/appnode:v1 27/09/2021 Docker 31 Image name (name space + repository + tag)
  • 32. Docker Images • List the images docker image ls 27/09/2021 Docker 32
  • 33. Docker Images • Execute your node application inside the docker docker container run –d –p 8080:8081 -–name my_appnode_container jadsonjs/appnode:v1 docker container ls 27/09/2021 Docker 33 Image name Container name Run in background Bind the 8081 NODE application port to 8080 HOST port
  • 34. Docker Images • Execute your node application inside the docker 27/09/2021 Docker 34
  • 35. Docker Images • Publish image to docker hub • Publish the image to my account do docker hub as a public image that other people can use. docker login docker push jadsonjs/appnode:v1 27/09/2021 Docker 35
  • 36. Docker Images • Publish image to docker hub • Publish the image to my account do docker hub as a public image that other people can use. 27/09/2021 Docker 36
  • 37. Docker Networks • If you are going to run 2 or more applications in 2 or more separate containers and need them to communicate. Must create a network between these containers docker network create my-app-net docker container run -–name api –d -p 8080:8080 -–network=my-app-net jadsonjs/appnode:v1 docker container run -–name mongodb -d -p 27017:27017 -e USER=user -e PASS=1234 -–network=my-app-net mongo:5.0.3 27/09/2021 Docker 37
  • 38. Docker Volumes • Used to save data if you kill and upload the container again. Example: Container of a database. • Link container file system with the host file system • This can be done via directory bind. In the format HOST : CONTAINER, similar with port bind docker container run -–name bancoDeDadosMongo -d -p 27017:27017 -e USER=user -e PASS=1234 -–network=api-net -v “/usr/local/mongodb:/data/db” mongo:5.0.3 27/09/2021 Docker 38 Bind the /data/db mongo db directory with /usr/local/mongodb HOST directory In other words, the data will be save in /usr/local/mongodb HOST directory
  • 39. Docker Volumes • Creating a volume docker volume create mongodb_vol docker container run -–name mongodb -d -p 27017:27017 -e USER=user -e PASS=1234 -–network=my-app-net -v “mongodb_vol:/data/db” mongo:5.0.3 27/09/2021 Docker 39 Bind the /data/db mongo db directory with a mongodb_vol create by the container mongodb_vol is a directory in HOST machine created and managed by container
  • 40. Docker Volumes • Creating a volume docker volume ls docker volume inspect mongo_db_vol 27/09/2021 Docker 40
  • 41. Vue JS Application on Docker 27/09/2021 Docker 41
  • 42. Vue JS Application on Docker • Let’s create a simple VUE calculator application with de command • vue create calculator-front-end • The application will be a simple calculator that will call a back-end application written in Java. • The front end application will be deployed using nginx server. • The back end application will be deployed in another Docker container. 27/09/2021 Docker 42
  • 43. Vue JS Application on Docker • Let’s create a simple VUE calculator application • We create a nginx.conf file in the project root that configure your “calculator” application • When somebody type “/calculator” on url, the nginx serve should execute the /calculator/index.html of a VUE Single Page Application project • This file will be copy into the container file system. 27/09/2021 Docker 43
  • 44. Vue JS Application on Docker • Let’s create a simple VUE calculator application • For the vue app work inside nginx server, we have to define a context to VUE application when execute on Docker, we make this in the vue.config.js file. 27/09/2021 Docker 44
  • 45. Vue JS Application on Docker • In the dockerfile file, we define some steps to build our image • Build Steps: • Download a “node” image • Create a temp directory “app” and copy package*.json files to it • Install all Vue dependences • Copy the other files and make the build of project • Execution Steps: • Now, download a image of nginx • Copy the vue “dist” directory content to nginx default directory: /usr/share/nginx renaming it. • And copy the nginx.conf file (in the root of the project) to nginx default configuration directory: /etc/nginx/ 27/09/2021 Docker 45
  • 46. Vue JS Application on Docker • Now, we need to build the image • docker build . -t calculator-front-end • After that, we create a network and run the docker container • This same network will be used by the back end container • docker network create calculator-net • docker run -d -p 8080:8080 –network=calculator-net calculator-front-end 27/09/2021 Docker 46
  • 47. Vue JS Application on Docker • When the container goes up, the ningx server will goes up also and make deploy of our application following the nginx.conf files • We can access the application on address: http://localhost:8080/calculator/ 27/09/2021 Docker 47
  • 48. Java Application on Docker 27/09/2021 Docker 48
  • 49. Java Application on Docker • We will create a simple Java spring boot back-end application for our calculator • We will use Gradle as a build tool. 27/09/2021 Docker 49
  • 50. Java Application on Docker • Now we will configure dockerfile file to create a docker image • Build Steps: • Download the gradle image • Create a workdir • Copy all files to this workdir • Run the gradle build • Executions steps: • Download JDK 11 image • Copy and rename the application jar • Expose the back end port • Execute the Java application when container goes up 27/09/2021 Docker 50
  • 51. Java Application on Docker • We can build the Java back end image with this command • docker build . -t calculator-back-end 27/09/2021 Docker 51
  • 52. Java Application on Docker • Now we can run the back end Java application with this command • PS.: The front end application should be already running (previous slides) • docker run -d -p 8081:8081 –network=calculator-net calculator-back-end 27/09/2021 Docker 52
  • 53. Java Application on Docker • If everything was ok, now we have a front end VUE.js application run with nginx server on a Docker calling a back end Java application run on Docker also. 27/09/2021 Docker 53
  • 56. Docker Compose • Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you can use a YAML file to configure and start several docker applications. • So, create a docker-compose.yaml file with the follow content 27/09/2021 Docker 56
  • 57. Docker Compose • First we define the version and the networks of our containers • We define a new network to the docker compose create it 27/09/2021 Docker 57
  • 58. Docker Compose • Now, we need to define our services (containers) • The first one is the VUE js front end application. • It uses the calculator-front-end image in port 8080:8080, using the calculator-net2 network and should starts after back-end container 27/09/2021 Docker 58
  • 59. Docker Compose • Now, we need to define our services (containers) • The second one is the Java back end application. • It uses the calculator-back-end image in port 8081:8081, using the same calculator- net2 network. 27/09/2021 Docker 59
  • 60. Docker Compose • Now, just execute the follow command: • docker compose up -d • This command will replace the follow two commands and simplify the docker execution • docker run -d -p 8080:8080 –network=calculator-net calculator-front-end • docker run -d -p 8081:8081 –network=calculator-net calculator-back-end • To stop the execution of containers, type: • docker compose down 27/09/2021 Docker 60
  • 61. References • https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on- ubuntu-20-04 • https://cli.vuejs.org/guide/deployment.html#docker-nginx • https://medium.com/bb-tutorials-and-thoughts/how-to-serve-vue-js-application-with-nginx- and-docker-d8a872a02ea8 • https://www.baeldung.com/dockerizing-spring-boot-application • https://docs.docker.com/language/java/build-images/ 27/09/2021 Docker 63