DevOps Classroom notes 21/Jan/2024

Multistage Dockerfiles

  • Building the technology specific packages also can be done as part of docker image building using multi stage Docker builds
  • structure
FROM <image> as stage1
...
...
...


FROM <image> as stage2
...
...
...

FROM <image> as stage3
...
...
...
  • Refer Here for official docs
  • Lets build spring pet clinic (maven, jdk 17, spring boot) Refer Here for code
  • Manual steps to build the application
# ensure jdk 17 is installed
# ensure maven is installed
  • Multistage dockerfile
FROM maven:3-amazoncorretto-17 AS build
ADD . /springpetclinic
WORKDIR /springpetclinic
RUN mvn package


FROM amazoncorretto:17-alpine-jdk
COPY --from=build /springpetclinic/target/spring-petclinic-3.2.0-SNAPSHOT.jar /spring-petclinic-3.2.0-SNAPSHOT.jar
EXPOSE 8080
# make this non root
CMD [ "java", "-jar", "/spring-petclinic-3.2.0-SNAPSHOT.jar" ]
  • Build the image and scan the image using trivy scanner
  • Installation Refer Here
  • Multistage dockerfile for nop commerce
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

WORKDIR /src                                                                    
COPY ./src ./

# restore solution
RUN dotnet restore NopCommerce.sln

WORKDIR /src/Presentation/Nop.Web   

# build project   
RUN dotnet build Nop.Web.csproj -c Release

# build plugins
WORKDIR /src/Plugins/Nop.Plugin.DiscountRules.CustomerRoles
RUN dotnet build Nop.Plugin.DiscountRules.CustomerRoles.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.ExchangeRate.EcbExchange
RUN dotnet build Nop.Plugin.ExchangeRate.EcbExchange.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.ExternalAuth.Facebook
RUN dotnet build Nop.Plugin.ExternalAuth.Facebook.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Misc.Brevo
RUN dotnet build Nop.Plugin.Misc.Brevo.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Misc.WebApi.Frontend
RUN dotnet build Nop.Plugin.Misc.WebApi.Frontend.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Misc.Zettle
RUN dotnet build Nop.Plugin.Misc.Zettle.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.MultiFactorAuth.GoogleAuthenticator
RUN dotnet build Nop.Plugin.MultiFactorAuth.GoogleAuthenticator.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Payments.CheckMoneyOrder
RUN dotnet build Nop.Plugin.Payments.CheckMoneyOrder.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Payments.CyberSource
RUN dotnet build Nop.Plugin.Payments.CyberSource.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Payments.Manual
RUN dotnet build Nop.Plugin.Payments.Manual.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Payments.PayPalCommerce
RUN dotnet build Nop.Plugin.Payments.PayPalCommerce.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Pickup.PickupInStore
RUN dotnet build Nop.Plugin.Pickup.PickupInStore.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Shipping.FixedByWeightByTotal
RUN dotnet build Nop.Plugin.Shipping.FixedByWeightByTotal.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Shipping.UPS
RUN dotnet build Nop.Plugin.Shipping.UPS.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Tax.Avalara
RUN dotnet build Nop.Plugin.Tax.Avalara.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Tax.FixedOrByCountryStateZip
RUN dotnet build Nop.Plugin.Tax.FixedOrByCountryStateZip.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Widgets.FacebookPixel
RUN dotnet build Nop.Plugin.Widgets.FacebookPixel.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Widgets.GoogleAnalytics
RUN dotnet build Nop.Plugin.Widgets.GoogleAnalytics.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Widgets.NivoSlider
RUN dotnet build Nop.Plugin.Widgets.NivoSlider.csproj -c Release
WORKDIR /src/Plugins/Nop.Plugin.Widgets.What3words
RUN dotnet build Nop.Plugin.Widgets.What3words.csproj -c Release

# publish project
WORKDIR /src/Presentation/Nop.Web   
RUN dotnet publish Nop.Web.csproj -c Release -o /app/published

WORKDIR /app/published

RUN mkdir logs
RUN mkdir bin


FROM mcr.microsoft.com/dotnet/aspnet:8.0
EXPOSE 5000
COPY --from=build /app/published /app
WORKDIR /app
CMD ["dotnet", "run","Nop.Web.dll", "--urls", "http://0.0.0.0:5000"]

Break till 8:05

Docker Registries

  • Docker Registries can store docker images which can be shared.
  • The default docker registry is docker hub
  • To push the images to docker hub
# login into dockerhub
docker login


* In Dockerhub we have two types of repositories
* private
* public
* To create a repository generally the naming convention is <username>/<repo-name>:<image-tag>

* Let push the image docker image push <image-name>

  • Generally enterprises use private docker registries, There are many providers
    • DockerHub Paid account
    • AWS Elastic Container registry
    • Azure Container Registry
    • Google Container Registry
    • jfrog

Lets create an Azure container registry and push the image

az login
  • Refer Here
  • Elastic contianer registry: refer classroom videp
Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a ReplyCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Exit mobile version
%%footer%%