Consideration for building Docker image for any application
- Right base image
- Steps for installing and configuring your application
- Expressing details about the ports on which your application works
- Commands to start your application.
Docker images in depth
- Docker image is collection of layers.
- Theroitically each layer is result of the change (RUN, COPY, ADD) will lead to creation of image layers
- Lets take the openjdk image
docker image pull openjdk:8and executedocker image inspect openjdk:8
- Lets try to create our new docker image with openjdk:8 as base image
FROM openjdk:8

- Now lets inspect myjdk:8 and look into layers

- myjdk:8 is exactly the collection of 7 image layers which openjdk:8 has
- Lets add some stuff to this image
FROM openjdk:8
RUN wget https://referenceappkhaja.s3-us-west-2.amazonaws.com/spring-petclinic-2.2.0.BUILD-SNAPSHOT.jar

- now lets inspect myjdk:8.1 for image layers

- myjdk 8.1 add approx 40 mb of file to existing openjdk:8 in the new layer added

- If the image layer which is used by new image which you are pull already exists docker image will not download it again

- Docker images can be built from scratch Refer Here
- docker image is collection of image layers

- Then what will container have one extra read write layer for the changes

Dockerfile IDE
- For developing Dockerfile any text editor can be used.
- In this series i will be using visual studio code + Docker extension from Microsoft added

Dockerfile instructions
-
Refer Here for the Dockerfile official docs
-
FROM: Using from instruction we select baseimage, always choose a base image with some tag not latest Refer Here
-
ADD and COPY: Are used to copy the contents into the docker image. ADD instruction can download the content from internet also (URI/URL).
- Refer Here for add instruction and Refer Here for copy instruction
-
EXPOSE: instruction lets Docker know that when the image is execute, the port and protocol defined will be exposed at runtime Refer Here
-
Refer Here for the sample used
-
ENTRYPOINT and CMD:
Docker container creation
- when ever you want to create a container execute run command
docker container run <image>:<tag>
- The entrypoint/cmd gets executed and as long as that command is executing container will be alive
- Refer Here for the sample docker image

- Now lets run this image and check for the containers

- Lets look at all the container status

- docker container has executed echo hello-world which completed its activity & now docker engine since the command execution is completed stopped the container.
- Now lets run the spc:trail1 with different cmd options

- Whatever command which is passed after image:tag in docker container run will replace CMD instruction
- Refer Here for the changes done
- Build the docker image

- In Docker entrypoint and CMD instruction can be written in two formats
- Exec form: Refer Here
- Shell form: Refer Here
- Docker container running modes:
- attached: This is default mode
- detached/background: in this mode your container will just show the container id and run in background
docker container run -d <image>:<tag>- interactive: In this mode we login into the terminal of container
docker container run -it <image>:<tag> <terminalpath>
- Docker container is a process isolation.
- It gets cpu and memory
- It gets storage (mount of image layers+read write layer)
- It gets network interface
- Network port mapping b/w docker host and containers

- Exercise: Try building a docker image for
- nop commerce: Refer Here take ubuntu:18 as a base image
- openmrs standalone: Refer Here
