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.
CodePudding user response:
You need to create the app directory first
FROM python:3.10.2-slim-bullseye
# Create directory
RUN mkdir /app
#Copy stuff into /app
COPY ./*.py /app
# set workdir as "/app"
WORKDIR /app
#run
python train.py
CodePudding user response:
The Dockerfile COPY directive has some fussy rules over the syntax of the right-hand side. The documentation currently states:
If multiple
<src>resources are specified, either directly or due to the use of a wildcard, then<dest>must be a directory, and it must end with a slash/.If
<dest>does not end with a trailing slash, it will be considered a regular file and the contents of<src>will be written at<dest>.
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 from WORKDIR that /app isn't a directory, it's the Python file.
Make sure the right-hand side of COPY ends with a slash:
COPY *.py /app/ # <-- ends with /
