Manual Image Build Process
Tags: linux, docker, python, beginners
Published: 2021-12-05 00:58:31

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 )

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bkyumt9txqtu5f5qxtq0.png)

> 
$/home/usr/Desktop/Docker/manual-build 

2)  **Open the manual-build folder in the IDE or text editor. To write source code.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qh04zdacxdh6t1wpz33m.png)

3)  **create two different files.**
For example, 

1) myfirst.py, to write minimal flask code inside it.( Hello_world )

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/597t69u5i21gwtz8h5h8.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74dwppfsthrhgq6v3aiq.png)

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ycztkzzwksiqiud7okzv.png)

5)  **start a python container( manual ) and open a shell.**

> sudo docker start -i manual

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ccoaqpr5xhq26t60xgt5.png)

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.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mql9283i3rgees6otnk6.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x6x9idlrbrhlk8v71dbz.png)

9) **Restart the container and double-check.**

> sudo docker start -i manual

> cd /app

> ls -l

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/42bsju3novattusowt4b.png)

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ff2egw9by5x7u9twfr9o.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s7efb1nukz29u6q64oh2.png)

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**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/03vpsu1kjw8k5l0bz6vb.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s020of8jv4tl8vxjaxtq.png)

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/

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fizyquphmlyjxbbovbkq.png)