I want to copy all of my python ,.py
, files in my folder to my /app
folder and according to this SO question I should be able to just do
FROM python:3.10.2-slim-bullseye
#Copy stuff into /app
COPY ./*.py /app
# set workdir as "/app"
WORKDIR /app
#run
python train.py
but it throws the error mkdir /var/lib/docker/overlay2/jonf4h3njxr8zj28bxlyw7ztd/merged/app: not a directory
when it reaches the third line WORKDIR /app
.
I have tried several "versions" i.e COPY *.py /app
, COPY /*.py /app
but neither works
If I just copy everything i.e COPY . /app
it works fine, but insted of floating my .dockerignore
with stuff I don’t need, I just want to copy my python-files only.
2
Answers
You need to create the app directory first
The Dockerfile
COPY
directive has some fussy rules over the syntax of the right-hand side. The documentation currently states:So when you
COPY
a single*.py
file to/app
without a trailing slash, the Dockerfile creates a file named/app
that’s the single Python file. Then you get the error fromWORKDIR
that/app
isn’t a directory, it’s the Python file.Make sure the right-hand side of
COPY
ends with a slash: