Docker Contd
Multi staged dockerfile
-
Refer Here for official docs
-
Sample 1: Use stage for unzipping and adding bin logs
FROM alpine:3 AS downloader
ARG DOWNLOAD_LOCATION="https://github.com/nopSolutions/nopCommerce/releases/download/release-4.60.4/nopCommerce_4.60.4_NoSource_linux_x64.zip"
ADD ${DOWNLOAD_LOCATION} /nopCommerce/nopCommerce_4.60.4_NoSource_linux_x64.zip
RUN apk update && \
apk add unzip && \
cd /nopCommerce && \
unzip nopCommerce_4.60.4_NoSource_linux_x64.zip && mkdir bin logs \
&& rm nopCommerce_4.60.4_NoSource_linux_x64.zip
FROM mcr.microsoft.com/dotnet/runtime:7.0
LABEL author="khaja"
EXPOSE 5000
COPY --from=downloader /nopCommerce /nopCommerce
ENV ASPNETCORE_URLS="http://0.0.0.0:5000"
EXPOSE 5000
WORKDIR /nopCommerce
CMD ["dotnet", "Nop.Web.dll"]
-
Sample 2: build the spring petclinic application from code using jdk17 and maven
-
steps:
- code is available over github
git clone https://github.com/spring-projects/spring-petclinic.git
- Ensure maven and jdk 17 exists.
mvn package
- Now copy the jar into spc image
-
Your steps:
- clone the spc repo
git clone https://github.com/spring-projects/spring-petclinic.git
- add the Dockerfile with following contents and build the image
FROM maven:3-amazoncorretto-17 AS builder
COPY . /spring-petclinic
RUN cd /spring-petclinic && mvn package
FROM amazoncorretto:17-alpine3.17
LABEL author="khaja"
LABEL organization="learningthoughts"
ARG USERNAME='petclinic'
ARG HOMEDIR='/petclinic'
ENV TEST=hello
RUN adduser -h ${HOMEDIR} -s /bin/sh -D ${USERNAME}
USER ${USERNAME}
WORKDIR ${HOMEDIR}
COPY --from=builder --chown=${USERNAME}:${USERNAME} /spring-petclinic/target/spring-petclinic-3.1.0-SNAPSHOT.jar "${HOMEDIR}/spring-petclinic-3.1.0-SNAPSHOT.jar"
EXPOSE 8080
CMD ["java", "-jar", "spring-petclinic-3.1.0-SNAPSHOT.jar"]
Tomorrow’s class => Pushing images to registries and docker image scanning
- Learn to push docker images to
- docker hub
- azure container registry
- elastic container registry
- jfrog
Next Steps:
- Entry point , Exec vs shell form, memory restrictions
- Docker container doesnot remember changes once the container is deleted => Layers and Volumes
- Networking (swarm)
- Container Orchestration
Like this:
Like Loading...