Difference between revisions of "Docker/C4/Advanced-Docker/English"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with "<div style="margin-left:1.27cm;margin-right:0cm;"></div> {| border="1" |- || '''Visual Cue''' || '''Narration''' |- |- | style="background-color:transparent;border-top:0.5pt...")
 
Line 1: Line 1:
<div style="margin-left:1.27cm;margin-right:0cm;"></div>
+
 
 
{| border="1"
 
{| border="1"
 
|-
 
|-
Line 5: Line 5:
 
|| '''Narration'''
 
|| '''Narration'''
 
|-
 
|-
|-
+
 
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show Slide:
+
|| Show Slide:
  
 
'''Title Slide'''
 
'''Title Slide'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Hello and welcome to the Spoken Tutorial on “'''Advanced Docker”.'''
+
|| Hello and welcome to the Spoken Tutorial on “'''Advanced Docker”.'''
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show Slide:
+
|| Show Slide:
  
 
'''Learning Objectives'''
 
'''Learning Objectives'''
  
<div style="color:#ff0000;"></div>
+
 
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | In this tutorial, we will learn how to
+
|| In this tutorial, we will learn how to,
* <div style="margin-left:1.27cm;margin-right:0cm;">Write a dockerfile for python automation environment configurations.</div>
+
* Write a dockerfile for python automation environment configurations.
* <div style="margin-left:1.27cm;margin-right:0cm;">Build a docker image from the dockerfile</div>
+
* Build a docker image from the dockerfile
* <div style="margin-left:1.27cm;margin-right:0cm;">Run containers using the docker image</div>
+
* Run containers using the docker image
* <div style="margin-left:1.27cm;margin-right:0cm;">Test the docker image to run python automation script</div>
+
* Test the docker image to run python automation script
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show Slide:
+
|| Show Slide:
  
 
'''System Requirements'''
 
'''System Requirements'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | To record this tutorial, I am using  
+
|| To record this tutorial, I am using  
* <div style="margin-left:1.27cm;margin-right:0cm;">'''Ubuntu Linux '''OS version '''22.04'''</div>
+
* '''Ubuntu Linux '''OS version '''22.04'''
* <div style="margin-left:1.27cm;margin-right:0cm;">'''Docker version 27.0.2'''</div>
+
* '''Docker version 27.0.2'''
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show Slide:
+
|| Show Slide:
  
 
'''Prerequisite'''
 
'''Prerequisite'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | To follow this tutorial,
+
|| To follow this tutorial,
* <div style="margin-left:1.27cm;margin-right:0cm;">You must have basic knowledge of using docker commands</div>
+
* You must have basic knowledge of using docker commands
* <div style="margin-left:1.27cm;margin-right:0cm;">For pre-requisite docker tutorials, please visit this website</div>
+
* For pre-requisite docker tutorials, please visit this website
  
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show slide:
+
|| Show slide:
  
 
'''Code files'''
 
'''Code files'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" |
+
||
* <div style="margin-left:1.27cm;margin-right:0cm;">The files used in this tutorial are provided in the '''Code files''' link.</div>
+
* The files used in this tutorial are provided in the '''Code files''' link.
* <div style="margin-left:1.27cm;margin-right:0cm;">Please download and extract the files.</div>
+
* Please download and extract the files.
* <div style="margin-left:1.27cm;margin-right:0cm;">Make a copy and then use them while practicing</div>
+
* Make a copy and then use them while practicing
  
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | Show files in the Downloads folder.
+
|| Show files in the Downloads folder.
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | I have created the code files required for this tutorial and saved it in my '''Downloads''' folder.
+
|| I have created the Code files required for this tutorial and saved it in my '''Downloads''' folder.
|-
+
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;"></div>
+
 
+
<div style="color:#000000;">Open '''Dockerfile'''</div>
+
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">The '''Dockerfile''' contains a set of instructions to create the Docker image.</div>
+
  
<div style="color:#000000;">It will set up the python environment required for automation inside docker image.</div>
+
Now we will have a look at each of the files available over here.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;"></div>
+
|| Open '''Dockerfile'''
 +
||The '''Dockerfile''' contains a set of instructions to create the Docker image.
  
<div style="color:#000000;">Open '''main.py'''</div>
+
It will set up the python environment required for automation inside docker image.
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | '''main.py''' file used to test if the Docker image is working correctly.
+
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | Open '''requirements.txt'''
+
|| Open '''main.py'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | '''requirements.txt''' file contains various packages to run the automation scripts of python.
+
|| '''main.py''' file used to test if the Docker image is working correctly.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">Open '''start_script.sh '''</div>
+
|| Open '''requirements.txt'''
 +
|| '''requirements.txt''' file contains various packages to run the automation scripts of python.
 +
|-
 +
||Open '''start_script.sh '''
  
<div style="color:#000000;">'''Highlight according to narration.'''</div>* <div style="color:#000000;margin-left:1.27cm;margin-right:0cm;">Usage: docker run my-python-app <filename> output,</div>
+
'''Highlight according to narration.'''  
 +
* Usage: docker run my-python-app <filename> output,
  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">'''start_script.sh''' is a bash script that runs every time when the container starts.</div>
+
||'''start_script.sh''' is a bash script that runs every time when the container starts.
  
<div style="color:#000000;">The script runs the specified Python file and returns the output.</div>
+
The script runs the specified Python file and returns the output.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | Open '''Checker.py'''
+
|| Open '''Checker.py'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">'''checker.py''' is the python file that we will test at the end.</div>
+
||'''checker.py''' is the python file that we will test at the end.
  
<div style="color:#000000;">The code checks if a given phrase has any spelling or grammatical mistakes.</div>
+
The code checks if a given phrase has any spelling or grammatical mistakes.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">Open Chatbot.py</div>
+
||Open Chatbot.py
  
<div style="color:#000000;">QnA_base.json</div>
+
QnA_base.json
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | '''Chatbot.py and QnA_base.json files '''are used to check the chatter through text.
+
|| '''Chatbot.py and QnA_base.json files ''' are used to check the chatter through text.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | Open a '''Dockerfike''' in '''text editor'''
+
|| Open a '''Dockerfike''' in '''text editor'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | Let us open the '''Dockerfile''' in the text editor.
+
|| Let us open the '''Dockerfile''' in the text editor.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">Only narration</div>
+
||Only narration
 
+
<div style="color:#000000;">'''Highlight Command'''</div>
+
  
<div style="color:#000000;">'''FROM ubuntu:22.04'''</div>
+
'''Highlight Command'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">Now we will see what various commands do in '''Dockerfile'''.</div>
+
  
<div style="color:#000000;">First, python:3.12.1 will be downloaded from the docker hub and used as a parent image.</div>
+
'''FROM ubuntu:22.04'''
 +
|| First, python:3.12.1 will be downloaded from the docker hub and used as a parent image.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">'''ENV DEBIAN_FRONTEND=noninteractive'''</div>
+
||'''ENV DEBIAN_FRONTEND=noninteractive'''
  
<div style="color:#000000;">'''ENV TZ=Etc/UTC'''</div>
+
'''ENV TZ=Etc/UTC'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | We set environment variables to configure time-zone data non-interactively.
+
|| We set environment variables to configure time-zone data non-interactively.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">'''RUN apt-get update && apt-get install -y \'''</div>
+
||'''RUN apt-get update && apt-get install -y \'''
  
<div style="color:#000000;"></div>
 
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;"></div>
 
  
<div style="color:#000000;">Run command will update the repositories.</div>
+
|| Run command will update the repositories.
  
<div style="color:#000000;">It will install the basic packages required for automation.</div>
+
It will install the basic packages required for automation.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | '''RUN python3 -m pip install --upgrade pip'''
+
|| '''RUN python3 -m pip install --upgrade pip'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | This''' '''command will upgrade pip to the latest version.
+
|| This''' '''command will upgrade pip to the latest version.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">'''RUN espeak --version && \'''</div>
+
||'''RUN espeak --version && \'''
  
<div style="color:#000000;">'''java -version && \'''</div>
+
'''java -version && \'''
  
<div style="color:#000000;">'''python3 --version'''</div>
+
'''python3 --version'''
  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | This command verify the installation of espeak, java and python
+
|| This command verify the installation of espeak, java and python
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | '''WORKDIR /app'''
+
|| '''WORKDIR /app'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | This command sets the '''app''' as the working directory in the container.
+
|| This command sets the '''app''' as the working directory in the container.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | '''COPY requirements.txt /app'''
+
|| '''COPY requirements.txt /app'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">Copy the requirements file into the '''app''' directory of the container.</div>
+
||Copy the requirements file into the '''app''' directory of the container.
  
<div style="color:#000000;">'''requirement.txt '''contains the name of the packages.</div>
+
'''requirement.txt '''contains the name of the packages.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | '''RUN pip install --no-cache-dir -r requirements.txt'''
+
|| '''RUN pip install --no-cache-dir -r requirements.txt'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | Next it will install all the packages specified in '''requirements.txt'''
+
|| Next it will install all the packages specified in '''requirements.txt'''
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">'''COPY . /app'''</div>
+
||'''COPY . /app'''
  
<div style="color:#000000;">'''RUN chmod +x /app/start_script.sh'''</div>
+
'''RUN chmod +x /app/start_script.sh'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">Then copy all the files into the container.</div>
+
||Then copy all the files into the container.
  
<div style="color:#000000;">'''chmod''' will set execute permission to '''start_script.sh'''</div>
+
'''chmod''' will set execute permission to '''start_script.sh'''
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | '''ENTRYPOINT ["/app/start_script.sh"]'''
+
|| '''ENTRYPOINT ["/app/start_script.sh"]'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;">Next define the entrypoint command.</div>
+
||Next define the entrypoint command.
  
<div style="color:#000000;">Here we are using python3 as the Entry point file.</div>
+
Here we are using python3 as the Entry point file.
  
<div style="color:#000000;">Close the''' text Editor.'''</div>
+
Close the''' text Editor.'''
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" |  
+
||  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | Now, let's build the Docker image using the Dockerfile we just created.
+
|| Now, let's build the Docker image using the Dockerfile we just created.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;"></div>
+
|| '''Terminal''' window opens
  
<div style="color:#000000;"></div>
+
'''Type command '''
  
<div style="color:#000000;"></div>
+
'''docker build -t python_automation .'''
  
<div style="color:#000000;"></div>
 
  
<div style="color:#000000;">'''Terminal''' window opens</div>
+
||  Open the terminal.
  
<div style="color:#000000;">'''Type command '''</div>
+
Change to the '''Downloads''' folder where the code files are available.
  
<div style="color:#000000;">'''docker build -t python_automation .'''</div>
+
The commands used in this tutorial are available in the '''commands.txt''' file in the code file.
  
<div style="color:#000000;"></div>
+
Copy and paste the commands wherever it is required.
  
<div style="color:#000000;"></div>
+
Type the command as shown and press Enter.
  
<div style="color:#000000;"></div>
+
This command builds the Docker image and tags it as '''python_automation'''.
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | <div style="color:#000000;"></div>
+
  
<div style="color:#000000;">Open the terminal.</div>
+
It will take sometime to build the image. Wait until it completes the process.
 
+
<div style="color:#000000;">Change to the '''Downloads''' folder where the code files are available.</div>
+
 
+
<div style="color:#000000;">The commands used in this tutorial are available in the '''commands.txt''' file in the code file.</div>
+
 
+
<div style="color:#000000;">Copy and paste the commands wherever it is required.</div>
+
 
+
<div style="color:#000000;">Type the command as shown and press Enter.</div>
+
 
+
<div style="color:#000000;">This command builds the Docker image and tags it as '''python_automation'''.</div>
+
 
+
<div style="color:#000000;">It will take sometime to build the image. Wait until it completes the process.</div>
+
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Type command '''docker images'''
+
|| Type command '''docker images'''
  
 
Highlight image ID
 
Highlight image ID
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Once the build is complete, the running process will stop.
+
|| Once the build is complete, the running process will stop.
  
 
To verify the created Docker image, type '''docker space images'''.
 
To verify the created Docker image, type '''docker space images'''.
Line 193: Line 174:
 
You will see the '''python_automation''' with its corresponding image ID in the list.
 
You will see the '''python_automation''' with its corresponding image ID in the list.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | In the '''terminal'''
+
|| In the '''terminal'''
  
 
'''docker run -it python_automation'''
 
'''docker run -it python_automation'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Next, let's run a container using the created image.
+
|| Next, let's run a container using the created image.
  
 
Type '''docker space run space hyphen it space python underscore automation'''  
 
Type '''docker space run space hyphen it space python underscore automation'''  
Line 206: Line 187:
 
Press''' ctrl + d''' to exit the '''shell.'''
 
Press''' ctrl + d''' to exit the '''shell.'''
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" |  
+
||  
 
+
|| Now we will test by using the '''main.py''' file.
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Now we will test by using the '''main.py''' file.
+
  
 
Type the command as shown.
 
Type the command as shown.
Line 219: Line 199:
  
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" |  
+
||  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" |  
+
|| Now let us test the python automation file.
 
+
Now let us test the python automation file.
+
  
 
We have a '''checker.py''' script which will check any spelling or grammatical mistakes.
 
We have a '''checker.py''' script which will check any spelling or grammatical mistakes.
Line 228: Line 206:
 
It requires a GUI to enter the text and display the output.
 
It requires a GUI to enter the text and display the output.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | '''Slide:'''
+
|| '''Slide:'''
  
 
'''Set up X11 forwarding'''
 
'''Set up X11 forwarding'''
  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" |
+
||
* <div style="margin-left:1.27cm;margin-right:0cm;">To run '''GUI applications''' inside a '''Docker container''', you need to set up '''X11 forwarding'''.</div>
+
* To run '''GUI applications''' inside a '''Docker container''', you need to set up '''X11 forwarding'''.
* <div style="margin-left:1.27cm;margin-right:0cm;">It runs applications on a remote server and displays them on your local machine.</div>
+
* It runs applications on a remote server and displays them on your local machine.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" |  
+
||   '''Type'''
 
+
'''Type'''
+
  
 
'''sudo xhost +local:docker'''
 
'''sudo xhost +local:docker'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Switch back to the terminal.
+
|| Switch back to the terminal.
  
 
Type '''sudo space xhost space +local:docke'''r  
 
Type '''sudo space xhost space +local:docke'''r  
Line 249: Line 225:
 
It allows '''Xserver''' for Docker on the local connection.
 
It allows '''Xserver''' for Docker on the local connection.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Type command  
+
|| Type command  
  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Next, run the container with X11 forwarding enabled.
+
|| Next, run the container with X11 forwarding enabled.
  
 
Type the following command as shown.
 
Type the following command as shown.
Line 259: Line 235:
 
It also mounts the '''Checker.py''' script into the container.
 
It also mounts the '''Checker.py''' script into the container.
  
It uses '''tkinter''', a <span style="background-color:#ffffff;color:#202122;">standard Python interface to the Tk GUI toolkit.</span>
+
It uses '''tkinter''', a standard Python interface to the Tk GUI toolkit.
  
 
If the container starts successfully a '''Spelling and Grammar Checker''' window will appear.
 
If the container starts successfully a '''Spelling and Grammar Checker''' window will appear.
Line 277: Line 253:
 
Close the window.
 
Close the window.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Narration only
+
|| Narration only
  
 
Show the code file  
 
Show the code file  
Line 283: Line 259:
 
'''chabot.py '''& '''QnA_base.json'''
 
'''chabot.py '''& '''QnA_base.json'''
  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Next, we will run a chatbot script.
+
|| Next, we will run a chatbot script.
  
 
Here you can see two files '''chabot.py '''& '''QnA_base.json'''
 
Here you can see two files '''chabot.py '''& '''QnA_base.json'''
Line 295: Line 271:
 
It learns new answers from the user, and updates the database accordingly'''.'''
 
It learns new answers from the user, and updates the database accordingly'''.'''
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | '''docker run -it -v $PWD/:/app/ python_automation Chatbot.py'''
+
|| '''docker run -it -v $PWD/:/app/ python_automation Chatbot.py'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Switch back to the terminal.
+
|| Switch back to the terminal.
  
 
To run this python script using docker image, type the command as shown
 
To run this python script using docker image, type the command as shown
Line 306: Line 282:
 
Press '''Enter''' to run the image
 
Press '''Enter''' to run the image
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | '''Terminal'''
+
|| '''Terminal'''
  
 
'''Type '''
 
'''Type '''
  
 
'''Hello'''
 
'''Hello'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | If the image ran successfully you can see the message from chatbot
+
|| If the image ran successfully you can see the message from chatbot
  
 
Saying '''Hello! I'm here to help you with your questions. Type 'quit' to exit.'''
 
Saying '''Hello! I'm here to help you with your questions. Type 'quit' to exit.'''
Line 325: Line 301:
 
Type ‘quit’ to exit the chatbot.n
 
Type ‘quit’ to exit the chatbot.n
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" |  
+
||  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;color:#000000;" | This is how we can work with the python scripts using this docker image.
+
|| This is how we can work with the python scripts using this docker image.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | '''Slides:'''
+
|| '''Slides:'''
  
 
'''Features of docker images'''
 
'''Features of docker images'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" |
+
||
* <div style="margin-left:1.27cm;margin-right:0cm;">Ensures the script runs consistently across different systems and environments</div>
+
* Ensures the script runs consistently across different systems and environments
* <div style="margin-left:1.27cm;margin-right:0cm;">Prevents conflicts by isolating the script from the host system</div>
+
* Prevents conflicts by isolating the script from the host system
* <div style="margin-left:1.27cm;margin-right:0cm;">Easily move and run the script on any Docker-compatible platform</div>
+
* Easily move and run the script on any Docker-compatible platform
* <div style="margin-left:1.27cm;margin-right:0cm;">Packages all dependencies, avoiding manual installations and version conflicts</div>
+
* Packages all dependencies, avoiding manual installations and version conflicts
* <div style="margin-left:1.27cm;margin-right:0cm;">Containers limit access, reducing potential security risks to the host system</div>
+
* Containers limit access, reducing potential security risks to the host system
  
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show Slide:  
+
|| Show Slide:  
  
 
'''Summary'''
 
'''Summary'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | This brings us to the end of this tutorial. Let us summarize.
+
|| This brings us to the end of this tutorial. Let us summarize.
  
 
In this tutorial, we have learnt how to
 
In this tutorial, we have learnt how to
* <div style="margin-left:1.27cm;margin-right:0cm;">Write a dockerfile for python automation environment configurations.</div>
+
* Write a dockerfile for python automation environment configurations.
* <div style="margin-left:1.27cm;margin-right:0cm;">Build a docker image from the docker file</div>
+
* Build a docker image from the docker file
* <div style="margin-left:1.27cm;margin-right:0cm;">Run containers using the docker image</div>
+
* Run containers using the docker image
* <div style="margin-left:1.27cm;margin-right:0cm;">Test the docker image to run python automation script</div>
+
* Test the docker image to run python automation script
  
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show Slide: '''About Spoken Tutorial project'''
+
|| Show Slide:  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | The video at the following link summarizes the '''Spoken Tutorial project'''.
+
 
 +
'''About Spoken Tutorial project'''
 +
|| The video at the following link summarizes the '''Spoken Tutorial project'''.
  
 
Please download and watch it
 
Please download and watch it
 
|-
 
|-
| style="background-color:#ffffff;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;" | Show Slide: '''Spoken Tutorial Workshops'''
+
|| Show Slide:
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.079cm;padding-right:0.191cm;" | <span style="background-color:#ffffff;">The&nbsp;</span><span style="background-color:#ffffff;">'''Spoken Tutorial Project'''</span><span style="background-color:#ffffff;">&nbsp;team </span>conducts workshops and gives certificates.
+
 
 +
'''Spoken Tutorial Workshops'''
 +
|| '''Spoken Tutorial Project'''conducts workshops and gives certificates.
  
 
For more details, please write to us.
 
For more details, please write to us.
 
|-
 
|-
| style="background-color:#ffffff;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;" | Show Slide:
+
|| Show Slide:
  
 
'''Answers for THIS Spoken Tutorial'''
 
'''Answers for THIS Spoken Tutorial'''
| style="background-color:#ffffff;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.095cm;padding-right:0.191cm;" | Please post your timed queries in this forum.
+
|| Please post your timed queries in this forum.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show Slide: '''FOSSEE Forum'''
+
|| Show Slide:
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | For any general or technical questions on '''Docker''', visit the FOSSEE forum and post your question.
+
 
 +
'''FOSSEE Forum'''
 +
|| For any general or technical questions on '''Docker''', visit the FOSSEE forum and post your question.
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Slide: '''Acknowledgement'''
+
|| Slide: '''Acknowledgement'''
  
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Spoken Tutorial Project was established by the Ministry of Education, Government of India
+
|| Spoken Tutorial Project was established by the Ministry of Education, Government of India
  
 
|-
 
|-
| style="background-color:transparent;border-top:0.5pt solid #000000;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:none;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" | Show slide:
+
|| Show slide:
  
 
'''Thank You'''
 
'''Thank You'''
| style="background-color:transparent;border:0.5pt solid #000000;padding-top:0cm;padding-bottom:0cm;padding-left:0.092cm;padding-right:0.191cm;" |  
+
|| This is Aditya Kushwaha, a FOSSEE Semester long intern 2024, IIT Bombay, signing off.
 
+
This is Aditya Kushwaha, a FOSSEE Semester long intern 2024, IIT Bombay, signing off.
+
  
 
Thanks for joining.
 
Thanks for joining.
 
|-
 
|-
 
|}
 
|}

Revision as of 11:46, 11 March 2025

Visual Cue Narration
Show Slide:

Title Slide

Hello and welcome to the Spoken Tutorial on “Advanced Docker”.
Show Slide:

Learning Objectives


In this tutorial, we will learn how to,
  • Write a dockerfile for python automation environment configurations.
  • Build a docker image from the dockerfile
  • Run containers using the docker image
  • Test the docker image to run python automation script
Show Slide:

System Requirements

To record this tutorial, I am using
  • Ubuntu Linux OS version 22.04
  • Docker version 27.0.2
Show Slide:

Prerequisite

To follow this tutorial,
  • You must have basic knowledge of using docker commands
  • For pre-requisite docker tutorials, please visit this website
Show slide:

Code files

  • The files used in this tutorial are provided in the Code files link.
  • Please download and extract the files.
  • Make a copy and then use them while practicing
Show files in the Downloads folder. I have created the Code files required for this tutorial and saved it in my Downloads folder.

Now we will have a look at each of the files available over here.

Open Dockerfile The Dockerfile contains a set of instructions to create the Docker image.

It will set up the python environment required for automation inside docker image.

Open main.py main.py file used to test if the Docker image is working correctly.
Open requirements.txt requirements.txt file contains various packages to run the automation scripts of python.
Open start_script.sh

Highlight according to narration.

  • Usage: docker run my-python-app <filename> output,
start_script.sh is a bash script that runs every time when the container starts.

The script runs the specified Python file and returns the output.

Open Checker.py checker.py is the python file that we will test at the end.

The code checks if a given phrase has any spelling or grammatical mistakes.

Open Chatbot.py

QnA_base.json

Chatbot.py and QnA_base.json files are used to check the chatter through text.
Open a Dockerfike in text editor Let us open the Dockerfile in the text editor.
Only narration

Highlight Command

FROM ubuntu:22.04

First, python:3.12.1 will be downloaded from the docker hub and used as a parent image.
ENV DEBIAN_FRONTEND=noninteractive

ENV TZ=Etc/UTC

We set environment variables to configure time-zone data non-interactively.
RUN apt-get update && apt-get install -y \


Run command will update the repositories.

It will install the basic packages required for automation.

RUN python3 -m pip install --upgrade pip This command will upgrade pip to the latest version.
RUN espeak --version && \

java -version && \

python3 --version

This command verify the installation of espeak, java and python
WORKDIR /app This command sets the app as the working directory in the container.
COPY requirements.txt /app Copy the requirements file into the app directory of the container.

requirement.txt contains the name of the packages.

RUN pip install --no-cache-dir -r requirements.txt Next it will install all the packages specified in requirements.txt
COPY . /app

RUN chmod +x /app/start_script.sh

Then copy all the files into the container.

chmod will set execute permission to start_script.sh

ENTRYPOINT ["/app/start_script.sh"] Next define the entrypoint command.

Here we are using python3 as the Entry point file.

Close the text Editor.

Now, let's build the Docker image using the Dockerfile we just created.
Terminal window opens

Type command

docker build -t python_automation .


Open the terminal.

Change to the Downloads folder where the code files are available.

The commands used in this tutorial are available in the commands.txt file in the code file.

Copy and paste the commands wherever it is required.

Type the command as shown and press Enter.

This command builds the Docker image and tags it as python_automation.

It will take sometime to build the image. Wait until it completes the process.

Type command docker images

Highlight image ID

Once the build is complete, the running process will stop.

To verify the created Docker image, type docker space images.

This command lists all the Docker images on your system.

You will see the python_automation with its corresponding image ID in the list.

In the terminal

docker run -it python_automation

Next, let's run a container using the created image.

Type docker space run space hyphen it space python underscore automation

We can see python interactive shell

This means that our docker image is running perfectly

Press ctrl + d to exit the shell.

Now we will test by using the main.py file.

Type the command as shown.

Main.py is the python file .

It will return an output saying This is a test python code.

This shows that the docker image is successfully running.

Now let us test the python automation file.

We have a checker.py script which will check any spelling or grammatical mistakes.

It requires a GUI to enter the text and display the output.

Slide:

Set up X11 forwarding

  • To run GUI applications inside a Docker container, you need to set up X11 forwarding.
  • It runs applications on a remote server and displays them on your local machine.
Type

sudo xhost +local:docker

Switch back to the terminal.

Type sudo space xhost space +local:docker

and press Enter.

It allows Xserver for Docker on the local connection.

Type command Next, run the container with X11 forwarding enabled.

Type the following command as shown.

This command mounts the X11 socket and sets the DISPLAY variable to enable GUI forwarding.

It also mounts the Checker.py script into the container.

It uses tkinter, a standard Python interface to the Tk GUI toolkit.

If the container starts successfully a Spelling and Grammar Checker window will appear.

You can test the checker by typing a mis-spelled word.

I will type the sentence Docker is amazing with a spelling mistake in the word amzing

Now click on the Check button.

It will show the spelling error returning the wrong spelling.

Correct the spelling and check it once more.

Now no errors were found.

Close the window.

Narration only

Show the code file

chabot.py & QnA_base.json

Next, we will run a chatbot script.

Here you can see two files chabot.py & QnA_base.json

QnA_base.json file acts as the database for the ChatBot.

It has question-answer pairs stored in a dictionary format.

This chatot.py script finds the closest matching question.

It learns new answers from the user, and updates the database accordingly.

docker run -it -v $PWD/:/app/ python_automation Chatbot.py Switch back to the terminal.

To run this python script using docker image, type the command as shown

Here the hyphen ti flag enables interactive shell

We need this to interact with chatbot

Press Enter to run the image

Terminal

Type

Hello

If the image ran successfully you can see the message from chatbot

Saying Hello! I'm here to help you with your questions. Type 'quit' to exit.

Your question:

Now you can type your question

Here I will type Hello and press Enter

You will get a response Bot says: hey there.

Type ‘quit’ to exit the chatbot.n

This is how we can work with the python scripts using this docker image.
Slides:

Features of docker images

  • Ensures the script runs consistently across different systems and environments
  • Prevents conflicts by isolating the script from the host system
  • Easily move and run the script on any Docker-compatible platform
  • Packages all dependencies, avoiding manual installations and version conflicts
  • Containers limit access, reducing potential security risks to the host system
Show Slide:

Summary

This brings us to the end of this tutorial. Let us summarize.

In this tutorial, we have learnt how to

  • Write a dockerfile for python automation environment configurations.
  • Build a docker image from the docker file
  • Run containers using the docker image
  • Test the docker image to run python automation script
Show Slide:

About Spoken Tutorial project

The video at the following link summarizes the Spoken Tutorial project.

Please download and watch it

Show Slide:
Spoken Tutorial Workshops
Spoken Tutorial Projectconducts workshops and gives certificates.

For more details, please write to us.

Show Slide:

Answers for THIS Spoken Tutorial

Please post your timed queries in this forum.
Show Slide:

FOSSEE Forum

For any general or technical questions on Docker, visit the FOSSEE forum and post your question.
Slide: Acknowledgement Spoken Tutorial Project was established by the Ministry of Education, Government of India
Show slide:

Thank You

This is Aditya Kushwaha, a FOSSEE Semester long intern 2024, IIT Bombay, signing off.

Thanks for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat