Dockerizing a python project
Dockerizing a Python Project
So this is a basic example of a docker file
# Set Base image to python 3.9 image
FROM python:3.9
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
EXPOSE 8080
ENV token sdajkadsjkslnladsnkln
CMD \["python", "app.py"\]
Assuming this is our folder structure
|-app.py
|-requirements.txt
|-dockerfile
Here is each line in the docker file:
-
Set the base image to the python runtime
-
Set our workDIR to
/app
-
Copy our project, into /app in the image
-
Run pip install to get dependencies
-
Tell the image that our app will run on port 8080 and that we need to expose it to the outer world VIA port-fowarding
-
Create and env called Token
-
The run command (which will be run when the image is run) is set to
python app.py
Finally we can build and run it like so
docker build -t imagename .
docker run imagename