Building Container Image Through Automation

This article is a continuation of my previous article. Here, we will work with the automation concept through which the container images can be created.

  • Previously, you were working in a PowerShell console. Continue the following with the same pane. We have saved the previous code in the Dockerfile. In that, there is a folder called websrc which is not created yet but is written in the code. So we shall proceed further by creating a folder called websrc. Run the following command now.

    mkdir websrc 

    Servers
  • Now, open the new folder which we have created. In this folder, create a new notepad file and add some text in it, and save it as HTML (save with HTML extension).

    Servers

  • Now, we shall build the Dockerfile which we created earlier. This file is in the web folder and we are currently in the same directory in our PowerShell. We shall build that file by using a tag name for it. For this, run the command...

    docker build -t web .

The dot in the above code is to indicate the current folder. 

  • This will now start to create an image for us along with the web server. The code gets executed step by step and it will take a couple of minutes to get completely done.

    Servers 
  • Now, clear the screen using cls and get all the available images by running the below command. There, you can find the newly created image with the name...

    docker images

    Servers

  • We shall now checkout our docker history so that the different layers of the newly created docker image can be seen. Here, the docker will be showing different layered time intervals because we have created it in multiple steps. Run the following command.

    docker history web

    Servers

  • The above method will let you create the docker images in an automated process. Here, we have created the image with some layers. If you want, you can create the images without having any layers by using the command RUN. 

  • Replace the code in the Dockerfile with the code given below and then build the container again. Check back the history of the container and you will be not getting any layers since the RUN command will let you execute the code without any layered concepts.
    1. FROM windowsservercore  
    2. RUN powershell.exe -Command \  
    3. $ErrorActionPreference = 'Stop'; \  
    4. Invoke-WebRequest https://www.python.org/ftp/python/3.5.1/python-3.5.1.exe -OutFile c:\python-3.5.1.exe ; \  
    5. Start-Process c:\python-3.5.1.exe -ArgumentList '/quiet InstallAllUsers=1 PrependPath=1' -Wait ; \  
    6. Remove-Item c:\python-3.5.1.exe -Force  


Similar Articles