Home > Enterprise >  Error while building the Docker image: "chown: cannot access 'app/csv/': No such file
Error while building the Docker image: "chown: cannot access 'app/csv/': No such file

Time:06-11

I am trying to create a Docker image for a python application and getting the following error

=> ERROR [7/9] RUN chown -R myuser:mygrp app/csv/ resources/datafeed.id                                                                                                           0.4s
------                                                                                                                                                                                  
 > [7/9] RUN chown -R myuser:mygrp app/csv/ resources/datafeed.id:                                                                                                                      
#11 0.325 chown: cannot access 'app/csv/': No such file or directory
#11 0.325 chown: cannot access 'resources/datafeed.id': No such file or directory
------
executor failed running [/bin/sh -c chown -R myuser:mygrp app/csv/ resources/datafeed.id]: exit code: 1

My Dockerfile is as follows :

FROM python:3.8-slim-buster

WORKDIR app/

COPY requirements.txt .

RUN pip install -r requirements.txt

RUN groupadd -r -g 2000 mygrp && useradd -u 2000 -r -g mygrp myuser

RUN chown -R myuser:mygrp app/csv/ resources/datafeed.id

RUN chmod -R 700 app/csv/

COPY app .

USER myuser

CMD [ "python", "./main_async.py" ]

Also my project structure does have these files:

Project-folder/app/csv
Project-folder/resources/datafeed.id

CodePudding user response:

You have your commands in the wrong order.

WORKDIR app/

...

RUN chown -R myuser:mygrp app/csv/ resources/datafeed.id
RUN chmod -R 700 app/csv/

COPY app .

The RUN <process> command will run whatever <process> is inside the container. In your current Dockerfile, you are chown-ing files you haven't copied yet inside the container.

Do the COPY first.

Make sure you are passing the correct arguments to COPY, which should generally be:

COPY <source on the host> <dest on the container>

So, if you are building from the Project-folder directory:

WORKDIR app

...

# Copy files from the host into the container.
# Since `WORKDIR` is already set, this copies
# all files in the current directory on
# host to under WORKDIR
COPY . .

RUN chown -R myuser:mygrp app/csv/ resources/datafeed.id
RUN chmod -R 700 app/csv/
  • Related