Namaste this post is an extension of the Docker image management. In this post, I would like to talk about how the Dockerfile content will work to build the Python web framework using the Flask app.
Let's consider a web platform we have multiple choices to use as a web application to run on docker container:
- Python web app using Flask
- Node.JS app
- Web app run with Go
For all these program execution structures is similar you must have 'app' folder. Where you can write your web application code.
FROM python:3.9.4-alpine COPY requirements.txt / RUN pip3 install -r /requirements.txt COPY . /app WORKDIR /app ENTRYPOINT ["./gunicorn.sh"]Here the base image used as Python3 version with apline which is thinner image. As pip installer will use requirement.txt file to install the dependencies libraries and packages required for running Flask.
COPY instruciton used to copy the files from docker host machine to container image.
WORKDIR is like cd command.
ENTRYPOINT instruction will take param which can be a script or command that could be executed
Step 1: Get the Flask Docker app Dockerflle from GitHub. You can have the following repository by Fort on the GitHub then you can use the
git cloneon Docker daemon running VM.
git clone https://github.com/BhavaniShekhar/Flask_Docker_App-1.git cd Flask_Docker_App-1/ ls -lrt
Step 2: Update some files and commit your changes. Here I've modified the index.html present in the
vi app/templates/index.html. Now, all set we can save the changes.
git add . git commit -m 'added text to index.html'Remember this will works only when you set the
git config --global user.emailand
git config --global user.name
Step 3: Build the docker image with the following command:
docker build -t flask:1.3 .
Step 4: Construct the container based on the flask image
docker run -d -p 8081:80 flask:1.3
Step 5: Python Flask based web app ready to use open a browser and try to access it with host ip and host port http://192.168.33.250:8081/
You can see the output as follows:
No comments:
Post a Comment