DevOps Classroom Series – 31/Aug/2021

Dockerfile Instructions

  • We have looked into
    • FROM
    • ADD/COPY
    • CMD
    • LABEL
    • EXPOSE
  • RUN instruction: This instruction executes any valide command
FROM ubuntu:xenial
RUN apt update && apt install apache2
  • Lets try to create a docker image with lamp stack Refer Here
FROM ubuntu:bionic
LABEL author='khaja'
FROM ubuntu:bionic
LABEL author='khaja'
RUN export DEBIAN_FRONTEND=noninteractive \
    && apt update && apt install apache2 -y \
    && apt install php libapache2-mod-php php-mysql -y \
    && apt install php-cli -y \
    && echo "<?php phpinfo();>" > /var/www/html/info.php 

  • Using local file and copy would be better
FROM ubuntu:bionic
LABEL author='khaja'
RUN export DEBIAN_FRONTEND=noninteractive \
    && apt update && apt install apache2 -y \
    && apt install php libapache2-mod-php php-mysql -y \
    && apt install php-cli -y
COPY info.php /var/www/html/info.php
  • WORKDIR: This instruction defines the working directory. If not specified / is the default workdir
  • CMD:
    • This instruction is executed when the container is created and can be overritten by passing arguments when creating container Preview
  • ENTRYPOINT:
    • This instruction is executed when the container is created and cannot be overritten by passing arguments when creating container
    • Generally in entrypoint we give executable path and in CMD we give arguments for the containers where the command to be executed when starting containers is fixed.
java -jar spc.jar


Give flexibility to run anything during creating container

CMD ["java", "-jar", "spc.jar"]


Dont give flexibility
ENTRYPOINT ["java", "-jar", "spc.jar"]

Give option on arguments to be passed
ENTRYPOINT ["java"]
CMD ["-jar", "spc.jar"]
  • We should be using ENTRYPOINT/CMD instructions to wait till the application is running
  • When we run applications we have two types of startups
    • commands which will start the application will not return till the application is killed. For these kind of applications directly add the command to CMD
      • Examples: java -jar <package>.jar, python main.py
    • commands which will start the application and will return immedietly. For these type of commands we need to look for alternative so that command will continue running as long as application is running.
      • Examples: service nginx start

Leave a Reply

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

Please turn AdBlock off
Floating Social Media Icons by Acurax Wordpress Designers

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