22 - CONTAINERIZATION Flashcards
Why containerization ?
Containerization addresses the need for consistency, portability, efficiency, and scalability in software development and deployment. It simplifies the packaging and distribution of applications, making it easier to manage complex systems and adapt to the demands of modern software development practices.
dockerhub setup
docker file structure for app, web, db
Docker-files
app/Dockerfile
web/Dockerfile
db/Dockerfile
docker-compose/yml
dockerhub repositories
app, db, web
create docker file for app
https://github.com/devopshydclub/vprofile-project
From openjdk:11 as BUILD_IMAGE
RUN apt update && apt install maven -y
RUN git clone repo_url
RUN cd vprofile-project && git checkout docker && mvn install
FROM tomcat:9-jre11
RUN rm -rf /usr/local/tomcat/webapps/*
COPY - -from=BUILD_IMAGE vprofile-project/target/vprofile-v2.war /usr/local/tomcat/webapps/ROOT
EXPOSE 8080
CMD [“Catalina.sh”, “run”]
WORKDIR /usr/local/tomcat
VOLUME /usr/local/tomcat/webapps
dockerfile for db
- FROM mysql:8.0.33
- LABEL “Project”=”name”
- LABEL “Author”=”Author name”
- ENV MYSQL_ROOT_PASSWORD=”vprodbpass”
- ENV MYSQL_DATABASE=”accounts”
- ADD db_backup.sql docker-entrypoint-initdb.d/db_backup.sql
dockerfile for web server
- FROM nginx
- LABEL Project
- LABEL Author
- RUN rm -rf /etc/nginx/conf.d/default.conf
- COPY nginvproapp.conf /etc/nginx/conf.d/vproapp.conf
run docker-compose file
version: ‘3.8’
services:
vprodb:
build:
context: ./Docker-files/db
image: vprocontainers/vprofiledb
container_name: vprodb
ports:
- ‘3306:3306’
volumes:
- vprodbdata:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=vprodbpass
vprocache01: image: memcached ports: - '11211: 11211' vpromq01: image: rabbitmq ports: - '15672: 15672' environment: - RABBITMQ_DEFAULT_USER=guest - RABBITMQ_DEFAULT_PASS=guest vproapp: build: context: ./Docker-files/app image: vprocontainers/vprofileapp container_name: vproapp ports: – '8080:8080' volumes: - vproappdata: /usr/local/tomcat/webapps vproweb: build: context: ./Docker-files/web image: vprocontainers/vprofileweb container_name: vproweb ports: – '80:80' volumes: - vproappdata: /usr/local/tomcat/webapps
volumes:
vprodbdata: {}
vproappdata: {}
build all images
docker compose build
start all containers
docker compose up
upload images to dockerhub
docker login
docker push
stop containers
docker compose down
remove all images
docker compose prune
containerize microservice project
https://github.com/devopshydclub/emartapp