DevOps Classroomnotes 17/Jun/2022

OTHER Dockerfile Directives

  • ENTRYPOINT: This directive is used to set the executable to started while creating container. For understanding refer Exploring CMD section below.
  • ENV
  • ARG
  • WORKDIR
  • USER

Exploring CMD

  • CMD will be executed when we are creating a container.
  • Whatever is written in CMD can be overriten while creating the container by passing the commands after image name.
    Preview
    Preview
  • Consider the following dockerfile
FROM alpine:3.10.4
LABEL author="khaja"
CMD ["echo", "hello"]
  • Build the image and run the container
    Preview
    Preview
  • Now consider the following Dockerfile
FROM alpine:3.10.4
LABEL author="khaja"
ENTRYPOINT [ "echo" ]
CMD ["hello"]

Preview

Exploring ARG

  • Consider the following Dockerfile
FROM openjdk:11
LABEL author="khaja"
LABEL project="qtdevops"
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar /spring-petclinic-2.4.2.jar
EXPOSE 8080
CMD [ "java", "-jar", "/spring-petclinic-2.4.2.jar" ]
  • In the above dockerfile while building the image the source from which we copy the file is used only while building the image and this might change in the future
  • Refer Here for the changes done
  • Now build the image
    Preview
  • Now lets experiment
    Preview
    Preview
  • Refer Here and Now lets build the image
    Preview
  • Lets change the build location while building the image
    Preview
  • ARGS can be passed while building the image whereas ENV can be passed while creating the container
    Preview
  • Note: If you need to change a varible during image build time as well as during CONTAINER CREATION Refer Here
    Preview
  • One possible use case is to download the file to any location
FROM openjdk:11
LABEL author="khaja"
LABEL project="qtdevops"
ARG SOURCE_JAR_LOCATION=https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar
ARG DESTINATION="/spring-petclinic-2.4.2.jar"
ADD  ${SOURCE_JAR_LOCATION} ${DESTINATION}
ENV DESTINATION=${DESTINATION}
RUN echo "ENV: ${TESTING}, ARG ${SOURCE_JAR_LOCATION}"
EXPOSE 8080
CMD [ "java", "-jar", "/spring-petclinic-2.4.2.jar" ]
  • Exercise Try using DESTINATION VARIABLE in CMD

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Wordpress Development Company

Discover more from Direct DevOps from Quality Thought

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

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube