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.

  • Consider the following dockerfile
FROM alpine:3.10.4
LABEL author="khaja"
CMD ["echo", "hello"]
  • Build the image and run the container

  • Now consider the following Dockerfile
FROM alpine:3.10.4
LABEL author="khaja"
ENTRYPOINT [ "echo" ]
CMD ["hello"]

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
  • Now lets experiment

  • Refer Here and Now lets build the image
  • Lets change the build location while building the image
  • ARGS can be passed while building the image whereas ENV can be passed while creating the container
  • Note: If you need to change a varible during image build time as well as during CONTAINER CREATION Refer Here
  • 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 ReplyCancel reply

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

Please turn AdBlock off
Customized Social Media Icons from Acurax Digital Marketing Agency

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%%