Docker ENV
- Sets an environment variable inside the image. Available at both build time (later steps) and run time (inside the running container), and can be overridden at docker run.
ENV key=value
ENV project=devOps
ENV APP_ENV=Prod
ENV JAVA_HOME=/user/jvm/openjdk-17-jdk/
ENV expose_port=8080
RUN echo "$JAVA_HOME"
EXPOSE $expose_port
FROM ubuntu:latest
ENV JAVA_VERSION=17 \
MAVEN_VERSION=3.8.6 \
BRANCH=main \
JARFILE=spring-petclinic-2.7.0.jar
ENV dbhost="" \
dbpassword=""
# Install dependencies in one layer
RUN apt-get update && \
apt-get install -y openjdk-${JAVA_VERSION}-jdk maven git && \
rm -rf /var/lib/apt/lists/*
# Clone repo (shallow clone for efficiency)
RUN git clone --depth 1 -b ${BRANCH} https://github.com/spring-projects/spring-petclinic.git
WORKDIR spring-petclinic
# Build and copy jar
RUN mvn clean package -DskipTests
RUN echo "curret path is $(pwd)"
WORKDIR /app
RUN cp -rf ../spring-petclinic/target/*.jar ${JARFILE}
# Cleanup source
RUN rm -rf ../spring-petclinic
# Use shell form CMD so env vars expand
CMD java -jar /app/${JARFILE}
override env at run time
docker run -dit -e JARFILE=spring-petclinic-2.7.0.jar –name demo-spring image:tag
Task
- try to install nopcommerce appliction in linux machine follow below steps Click here get steps to install nopcommerce
