DevOps Classroom Series – 28/Jan/2020

Importance of Tags in Docker

  • Format is <image-name>:<tag>
  • Ex: openjdk:8, jenkins:1.609.2
  • In docker if the tag is not specified, LATEST is applied
FROM tomcat   ===  FROM tomcat:LATEST
  • note: in FROM instruction always specify tag and also while building images

Dockerfile instructions


  • Create a Dockerfile with some cmd
FROM openjdk:8
RUN wget
CMD ["java", "-jar", "spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar"]
  • create a docker image (for tag use ddmmyy)
docker image build -t spc:280120 .
docker image build -t spc:1.0-280120

  • list the docker images
docker image ls
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
spc                 1.0-280120          4c0dd4eb112b        59 seconds ago      536MB
spc                 280120              4c0dd4eb112b        59 seconds ago      536MB
openjdk             8                   8c6851b1fc09        5 days ago          488MB

# for spc:280120 and 1.0-280120 we have same image id, same image id means same image to docker 
  • To create a container
docker container run -d -p 8080:8080 spc:280120
# creates a new container and runs CMD from Dockerfile

docker container run -d -p 8081:8080 spc:280120 echo helloworld
# Creates a new container and CMD in Dockerfile will be overriden with echo helloworld 
  • Entrypoint instruction also executes when creating a new container, the differnce with CMD is ENTRYPOINT cannot be overriten.
  • When you have written both ENTRYPOINT and CMD, ENTRYPOINT will be executable and CMD will be arguments
FROM openjdk:8
CMD ["hello"]
  • Now if we run a container after creating the image (demo)
docker container run image
# hello

docker container run image how are you
how are you
  • Containers will be alive as long as the command in ENTRYPOINT and CMD instruction is executing

Other instructions

  • LABEL: This instruction adds metadata
FROM openjdk:8
LABEL author=khaja
LABEL org=qt
  • ADD and COPY:
    • These instructions are used to copy the external files (file from host or from http(s)) into the docker image
    • ADD and copy both takes two arguments source and destination
    • ADD can copy the contents from file system and URLs
    • COPY can copy the contents only from file system
FROM openjdk:8
ADD /spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar
CMD ["java", "-jar", "spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar"]

Leave a Reply

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

About learningthoughtsadmin