--- .dockerignore | 13 +++++++++++++ .gitignore | 1 + Dockerfile | 13 +++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ae20a5b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# Editor crud files +*~ +\#*# +.vscode +.idea +.git + +# Artifacts +__pycache__ + +# Personal +/generic-updater +/configuration.py diff --git a/.gitignore b/.gitignore index f276bd1..dfb5a99 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ *~ \#*# .vscode +.idea # Artifacts __pycache__ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..df3ef97 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.9-buster + +WORKDIR /workdir + +COPY ./requirements.txt /workdir/requirements.txt + +RUN pip install -r requirements.txt + +COPY . /workdir + +EXPOSE 3000 + +CMD python index.py \ No newline at end of file -- 2.30.0
Hi, I'm finally getting to look at this. Thank you so much for your patience. > +/configuration.py Did you mean to put the main configuration file in dockerignore? > +COPY ./requirements.txt /workdir/requirements.txt > + > +RUN pip install -r requirements.txt > + > +COPY . /workdir Is there a reason why you don't `COPY .` straight away? Why 2 copy operations?
>> +/configuration.py > > Did you mean to put the main configuration file in dockerignore? Yes, my understanding is that it’s preferred to avoid giving a default configuration file to users, so we avoid copying it in the docker image. In order to run it a user need to create a configuration.py file and mount it inside the container from the local filesystem. Correct me if something is wrong here. >> +COPY ./requirements.txt /workdir/requirements.txt >> + >> +RUN pip install -r requirements.txt >> + >> +COPY . /workdir > > Is there a reason why you don't `COPY .` straight away? Why 2 copy > operations? This really is an optimisation on the way docker builds the image and it’s not strictly needed but a nice to have. When docker builds an image it runs every instruction one at a time and cache it in a layer. By separating pip install from the code copy means that as long as you don’t change the requirements.txt file dependencies will not be re-downloaded during each build run. Another big advantage is that layer cache works even across images for users: let’s say I already have a working image of cloudtube locally that is tagged :v1. Tomorrow a new version :v2 is released, this new version have the same dependencies as :v1 but lots of changes across the python source files. By using the cache I only have to download the changed source files and not all the dependencies again. If, instead, you first run COPY . /workdir and then run pip install the cache will be invalidated by any small change in any file that is part of the project. The final resulting image will be the same but you’ll lose all the caching benefits.