Can't copy specific files to /app in a Dockerfile

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.

>Solution :

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

Leave a Reply