Dockerfile
This article is the knowledge acquired on creating a simple Dockerfile as part of IIEC Rise 1.0 campaign under the mentorship of Vimal Daga Sir.
In this session we would be understanding the present scenario in container world where we run some additional softwares inside containers and also the steps to automate this.
Present scenario:
Consider the example, where we want to run python inside a container. For this, we require a base OS and then on top of this, we would run python program.
Conventional method to achieve this:
- Pull the latest image of BaseOS from docker hub. Here we selected CentOS.
- Run this CentOSimage to start a container. os1 is the name of the container.
- As CentOS comes with yum preconfigured, use it to install Python.
Now run command "python3".
Observing the above process closely we can see that,
1. We have used image FROM CentOS, and then created a container using this image.
2. RUN a command "yum install python36" to install python3.6 inside this container.
If we need to have multiple containers ( which run CentOS and Python36 inside ) then the above architecture would be a time consuming process. Instead of following above process we can simple create a custom image which has CentOS as Base operating system and also has Python36 installed in it.
What is Docker file..?
Dockerfile is one of the way to create a custom image. Technically it's a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build (which executes the Dockerfile), users can create an automated build that executes several command-line instructions in succession.
Note: The alphabet 'D' in Dockerfile should be in uppercase.
How to create Docker file..?
Add below content inside Dockerfile.
Keywords in Dockerfile
- FROM will indicate from which image the base OS will run.
- RUN will indicate the commands to be run inside the container.
Now the Dockerfile is ready to be build.
Use command, docker build -t <image_name> : <tag_name>
Here we have used rise as image name and v1 as tag
Now we can see the rise image has been successfully created.
Now we can utilise this image and launch containers.