31
Manual Image Build Process
For learning purpose, we're making a manual docker image. The term "best practice" relates to the process of creating an automated image. If we create a manual image in Docker, we must keep it up to date as our source code changes. As a consequence, the Process needs a significant amount of time and effort.
OS: Unix systems ( Ubuntu )
OS: Unix systems ( Ubuntu )
In the container, we'll run a simple flask application. We'll create an Image from a container once it's ready.
1) create a directory
below created a manual-build directory in the host
below created a manual-build directory in the host

$/home/usr/Desktop/Docker/manual-build
2) Open the manual-build folder in the IDE or text editor. To write source code.

3) create two different files.
For example,
For example,
1) myfirst.py, to write minimal flask code inside it.( Hello_world )

2) start-app.sh, a script that will execute in the Image.

4) make a container with a base image python
sudo docker create -it --name manual -p 5002:5002 python /bin/sh
The given interactive container(-it) name is manual which runs at port 5002.

5) start a python container( manual ) and open a shell.
sudo docker start -i manual

6) In the python base container, add /app dir
once /app dir is created exit from the shell and it will get back to host directory where manual-build folder is located.
once /app dir is created exit from the shell and it will get back to host directory where manual-build folder is located.

7) Copy flask.py from the manual-build folder to the docker/app directory.
8) Copy the start-app.py file from the manual-build folder to the docker/app directory.
The following command will copy files from the host to container.
sudo docker cp myfirst.py manual:/app
sudo docker cp start-app.sh manual:/app

9) Restart the container and double-check.
sudo docker start -i manual
cd /app
ls -l

10) Write the.sh script's execution.
chmod +x start-app.sh
11) Install the flask inside the container.
pip install flask
Once, flask is installed in the container then execute start-app.sh script with following command.
./start-app.sh or sh start-app.sh


The flask application works perfectly as we expected with port 5000.Container(manual ) is ready to ship.
12) create an image from a ready container
Once, container is ready. use commit in the docker to create new custom image
Sudo docker commit manual manual-image:1.1
manual-image is name of new custom image and 1.1 tag is given to it.
13) Run the newly formed image


Again, execute start-app.sh script in the manual-build:1.1 image. Now, Image works perfectly in the browser with given IP http://172.17.0.2:5000/

31