Introduction
Peace to you all , Here is the Link to my previous blogs, Where I have posted about Docker, Containers and DevOps.
This is Day 7 of documenting my DevOps journey .
This blog focuses on Dockerfile and its commands/instructions.
Getting Started
Building images through Dockerfile follows layered approach.
This means that every instruction we write is taken as a separate layer and the former layer provides for the latter layer.
We will get more familiar with this layered approach in the coming times.
Instructions
We will look at each instruction which can be found on a basic Dockerfile.
FROM
The FROM instruction is mandatory for creating an image.
It creates the base image for building the following instructions.
There can be multiple FROM in a DockerFile.
We can also provide any name for referencing in the later instructions using ‘AS’ instruction but not mandatory.
FROM nginx AS base-image
Here FROM takes the image nginx , if present locally it will take that, else it will pull it from dockerhub. The 'AS' sets a name for the nginx image as base-image ( it can be anything ).
ARG
This helps in storing a default value in a variable or getting the value on build time and could be used in FROM and many instructions.
ARG version-arg=latest
FROM nginx:${version-arg}
The ARG passes latest as value to version-arg variable and it is used in FROM instruction by calling the name of the variable.
WORKDIR
Sets the working directory for the subsequent instructions to come.
This can be used for many reasons where we need some instruction to happen in a different folder and some instruction in a different folder.
WORKDIR path
EXPOSE
This is to say that docker container listens on the specified port.
Also , we can mention the protocol prefixed with a slash.
EXPOSE 80
EXPOSE 443/tcp
RUN
This executes any command followed by 'RUN', commits it to the current image and that image is used for the following instructions.
We can also pass parameters for running the ‘RUN’ instruction.
RUN <command>
RUN ["exec","param1","param2"]
COPY
Copies files from the host to the filesystem of the container.
COPY . /usr/share/nginx/html
The '.' represents the current folder of the host . So the current folder is copied to the respective folder mentioned on the container.
Conclusion
These are very few instructions on docker , but these are predominantly used for creating images and in many cases it is sufficient. We will try to cover the rest in the upcoming blogs.
What have we done
We learnt about, what are the basic instructions of docker and how some instructions are written to the Dockerfile.
See you Tomorrow
Okay . So hold on, stay with me as we get to know docker more and DevOps even more.
Okay Then , Will get back Tomorrow with more!
Peace be upon you!