Difference between revisions of "Docker/C4/Advanced-Docker/English"
| Line 6: | Line 6: | ||
|- | |- | ||
| − | || Show Slide: | + | || '''Show Slide''': |
'''Title Slide''' | '''Title Slide''' | ||
|| Hello and welcome to the Spoken Tutorial on “'''Advanced Docker”.''' | || Hello and welcome to the Spoken Tutorial on “'''Advanced Docker”.''' | ||
|- | |- | ||
| − | || Show Slide: | + | || '''Show Slide''': |
'''Learning Objectives''' | '''Learning Objectives''' | ||
| Line 29: | Line 29: | ||
* '''Docker version 27.0.2''' | * '''Docker version 27.0.2''' | ||
|- | |- | ||
| − | || Show Slide: | + | || '''Show Slide''': |
'''Prerequisite''' | '''Prerequisite''' | ||
|| To follow this tutorial, | || To follow this tutorial, | ||
* You must have basic knowledge of using docker commands | * You must have basic knowledge of using docker commands | ||
| − | * For pre-requisite | + | * For pre-requisite Docker tutorials, please visit this website |
|- | |- | ||
| − | || Show slide: | + | || '''Show slide''': |
'''Code files''' | '''Code files''' | ||
| Line 47: | Line 47: | ||
|- | |- | ||
|| Show files in the Downloads folder. | || Show files in the Downloads folder. | ||
| − | || I have created the Code files required for this | + | || I have created the Code files required for this tutorials and saved it in my '''Downloads''' folder. |
Now we will have a look at each of the files available over here. | Now we will have a look at each of the files available over here. | ||
|- | |- | ||
|| Open '''Dockerfile''' | || Open '''Dockerfile''' | ||
| − | ||The '''Dockerfile''' contains a set of instructions to create the Docker image. | + | ||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. | + | It will set up the python environment required for automation inside '''docker image'''. |
|- | |- | ||
|| Open '''main.py''' | || Open '''main.py''' | ||
| Line 104: | Line 104: | ||
|- | |- | ||
|| '''RUN python3 -m pip install --upgrade pip''' | || '''RUN python3 -m pip install --upgrade pip''' | ||
| − | || This | + | || This command will upgrade pip to the latest version. |
|- | |- | ||
||'''RUN espeak --version && \''' | ||'''RUN espeak --version && \''' | ||
| Line 112: | Line 112: | ||
'''python3 --version''' | '''python3 --version''' | ||
| − | || This command verify the installation of espeak, java and python | + | || This command verify the installation of espeak, java and python. |
|- | |- | ||
|| '''WORKDIR /app''' | || '''WORKDIR /app''' | ||
| Line 120: | Line 120: | ||
||Copy the requirements file into the '''app''' directory of the container. | ||Copy the requirements file into the '''app''' directory of the container. | ||
| − | ''' | + | '''requirements.txt '''contains the name of the packages. |
|- | |- | ||
|| '''RUN pip install --no-cache-dir -r requirements.txt''' | || '''RUN pip install --no-cache-dir -r requirements.txt''' | ||
| Line 130: | Line 130: | ||
||Then copy all the files into the container. | ||Then copy all the files into the container. | ||
| − | + | ||
|- | |- | ||
|| '''ENTRYPOINT ["/app/start_script.sh"]''' | || '''ENTRYPOINT ["/app/start_script.sh"]''' | ||
| − | || | + | ||Here we are using python3 as the Entry point. |
| − | + | ||
| − | Here we are using python3 as the Entry point | + | |
Close the''' text Editor.''' | Close the''' text Editor.''' | ||
| Line 153: | Line 151: | ||
Change to the '''Downloads''' folder where the code files are available. | 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 | + | 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. | Copy and paste the commands wherever it is required. | ||
| Line 161: | Line 159: | ||
This command builds the Docker image and tags it as '''python_automation'''. | 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. | + | It will take sometime to build the image. |
| + | |||
| + | Wait until it completes the process. | ||
|- | |- | ||
|| Type command '''docker images''' | || Type command '''docker images''' | ||
| Line 180: | Line 180: | ||
Type '''docker space run space hyphen it space python underscore automation''' | Type '''docker space run space hyphen it space python underscore automation''' | ||
| + | and press Enter. | ||
| − | We can see '''python interactive shell''' | + | We can see '''python interactive shell'''. |
| − | This means that our docker image is running perfectly | + | This means that our docker image is running perfectly. |
| − | Press''' ctrl + | + | Press''' ctrl + D''' to exit the '''shell.''' |
|- | |- | ||
| − | || | + | || '''Main.py '''is the python file . |
|| Now we will test by using the '''main.py''' file. | || Now we will test by using the '''main.py''' file. | ||
| − | Type the command as shown. | + | Type the command as shown and press Enter. |
| − | |||
It will return an output saying '''This is a test python code.''' | It will return an output saying '''This is a test python code.''' | ||
| Line 199: | Line 199: | ||
|- | |- | ||
| − | || | + | || cursor on terminal |
|| Now let us test the python automation file. | || Now let us test the python automation file. | ||
| Line 217: | Line 217: | ||
'''sudo xhost +local:docker''' | '''sudo xhost +local:docker''' | ||
| − | || Switch back to the terminal | + | || Switch back to the terminal and |
| − | Type '''sudo space xhost space +local: | + | Type '''sudo space xhost space +local:docker'''. |
and press Enter. | and press Enter. | ||
| Line 226: | Line 226: | ||
|- | |- | ||
|| Type command | || Type command | ||
| − | |||
|| 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 and press Enter. |
This command mounts the '''X11 socket '''and sets the '''DISPLAY''' variable to enable GUI forwarding. | This command mounts the '''X11 socket '''and sets the '''DISPLAY''' variable to enable GUI forwarding. | ||
| Line 235: | Line 234: | ||
It also mounts the '''Checker.py''' script into the container. | It also mounts the '''Checker.py''' script into the container. | ||
| − | It uses '''tkinter''', | + | It uses '''tkinter''', as 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 269: | Line 268: | ||
This''' chatot.py '''script finds the closest matching question. | This''' chatot.py '''script finds the closest matching question. | ||
| − | It learns new answers from the user, and updates the database accordingly | + | It learns new answers from the user, and updates the database accordingly. |
|- | |- | ||
|| '''docker run -it -v $PWD/:/app/ python_automation Chatbot.py''' | || '''docker run -it -v $PWD/:/app/ python_automation Chatbot.py''' | ||
| Line 289: | Line 288: | ||
|| 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.''' | ||
'''Your question:''' | '''Your question:''' | ||
| Line 299: | Line 300: | ||
You will get a response '''Bot says: hey there'''. | You will get a response '''Bot says: hey there'''. | ||
| − | Type ‘quit’ to exit the chatbot. | + | Type ‘quit’ to exit the chatbot. |
|- | |- | ||
|| | || | ||
| Line 336: | Line 337: | ||
|| Show Slide: | || Show Slide: | ||
| − | + | '''Spoken Tutorial Workshops''' | |
|| '''Spoken Tutorial Project'''conducts workshops and gives certificates. | || '''Spoken Tutorial Project'''conducts workshops and gives certificates. | ||
For more details, please write to us. | For more details, please write to us. | ||
|- | |- | ||
| − | || Show Slide: | + | || '''Show Slide''': |
'''Answers for THIS Spoken Tutorial''' | '''Answers for THIS Spoken Tutorial''' | ||
|| Please post your timed queries in this forum. | || Please post your timed queries in this forum. | ||
|- | |- | ||
| − | || Show Slide: | + | || '''Show Slide''': |
'''FOSSEE Forum''' | '''FOSSEE Forum''' | ||
|| For any general or technical questions on '''Docker''', visit the FOSSEE forum and post your question. | || For any general or technical questions on '''Docker''', visit the FOSSEE forum and post your question. | ||
|- | |- | ||
| − | || Slide: '''Acknowledgement''' | + | || '''Show Slide''': |
| + | |||
| + | '''Acknowledgement''' | ||
|| 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 | ||
|- | |- | ||
| − | || Show slide: | + | || '''Show slide''': |
'''Thank You''' | '''Thank You''' | ||
Latest revision as of 16:12, 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,
|
| Show Slide:
System Requirements |
To record this tutorial, I am using
|
| Show Slide:
Prerequisite |
To follow this tutorial,
|
| Show slide:
Code files |
|
| Show files in the Downloads folder. | I have created the Code files required for this tutorials 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.
|
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.
requirements.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.
|
| ENTRYPOINT ["/app/start_script.sh"] | Here we are using python3 as the Entry point.
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 and press Enter. We can see python interactive shell. This means that our docker image is running perfectly. Press ctrl + D to exit the shell. |
| Main.py is the python file . | Now we will test by using the main.py file.
Type the command as shown and press Enter.
This shows that the docker image is successfully running. |
| cursor on terminal | 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 |
|
| Type
sudo xhost +local:docker |
Switch back to the terminal and
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 and press Enter. 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, as 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. |
| This is how we can work with the python scripts using this docker image. | |
| Slides:
Features of docker images |
|
| Show Slide:
Summary |
This brings us to the end of this tutorial. Let us summarize.
In this tutorial, we have learnt how to
|
| 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. |
| Show 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. |