Wednesday, November 29, 2023

Docker File PYTHON Installation

 We need to create three files 

1 vi requirements.txt

2 py.dockerfile

3 index.py


Write the following code in the requirements.txt

 vi requirements.txt


flash
boto
redis

Write the following code in the py.dockerfile




FROM python:alpine3.7

COPY . /app

WORKDIR /app

RUN pip install -r requirements.txt

EXPOSE 5000

CMD python ./index.py


Write the  following code in the index.py

 vi index,py

from flash import Flash
app= Flash(__name__)
@app.route("/")
def hello()l
     return "Hello world!"
if __name__==  "__main__":
    app.run(host="0.0.0.0", port=int("5000"), debug=True)

Finally run the docker build command

docker build -f py-dockerfile . -t hello-python:2.2
























Now, run the docker

docker run  -dit --name hello-py -p 5000:5000 hello-python:2.2

to keep running in the foreground use this command

docker run  -dit --name hello1-py -p 5000:5000 hello-python:2.2 tail -f















No comments:

Post a Comment

Thank you for visiting my blog

Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...