Dockerfile Instructions and Image Creations
-
To create a docker container we need an image.
-
Applications will have different versions, To accomodate this in docker container images, Docker images have tags.
-
The syntactic name of docker image
<image-name>:<tag-name>. -
If we don’t pass the tag-name the default tag
latestwill be applied. -
To create any Docker image, we need to know the manual steps for configuring and Running the application.
-
To make the process of creating docker images simple, Docker has `Dockerfile“ which is text file and contains instructions on how to build a container image.
-
This is declarative way of building images
-
Refer Here for the Dockerfile instructions and reference
-
Lets start with simple instructions
- FROM:
- Using this we define what is the base image for building our custom application image
FROM <base-image>:<tag>- It is recommended not to use the latest tag prefer specific tags over here
- If you really want to start to build a custom image with out any specific base image
FROM scratch - Refer Here
- LABEL: Adds metadata to the image Refer Here
- ADD: This instruction can be used to copy the files from http or docker host into docker image
ADD <source> <destination>- COPY: This instruction can be used to copy the files from docker host into docker image
COPY <source> <destination>- RUN
- EXPOSE: Expose instruction infor Docker that the container is listenting to the specific netowrk ports
EXPOSE <port> [<port>/<protocol>]- CMD: This instruction executes the command when the container is created Refer Here
- FROM:
-
The Dockerfile for springpetclinic which we have created is
FROM openjdk:11
LABEL author="khaja ibrahim"
LABEL organization="quality thought"
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar /spring-petclinic.jar
EXPOSE 8080
CMD [ "java", "-jar", "/spring-petclinic.jar" ]
- Now lets try to build a docker image
docker image build -t <image-name>:<tag> <path to folder where Dockerfile>
docker image build -t <image-name>:<tag> -f <path to Dockerfile>

- We can alos use the slim versions from base image if available
FROM openjdk:11-slim
LABEL author="khaja ibrahim"
LABEL organization="quality thought"
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/spring-petclinic-2.4.2.jar /spring-petclinic.jar
EXPOSE 8080
CMD [ "java", "-jar", "/spring-petclinic.jar" ]
- Exercise: Try create an docker container image for gameoflife
- Package file: https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/gameoflife.war
- This file will run on tomcat 9 version with java version 8 and this war file has to be copied into the webapps folder of tomcat
- This application will use tomcat’s port which is 8080
FROM tomcat:jdk8
LABEL author="khaja"
EXPOSE 8080
ADD https://referenceapplicationskhaja.s3.us-west-2.amazonaws.com/gameoflife.war /usr/local/tomcat/webapps/gameoflife.war
