Search code examples
dockerdockerfiledocker-build

"No such file or directory" what's wrong in this Dockerfile?


I am playing with a Dockerfile and I have this:

ARG PUID=1000
ARG PGID=1000
RUN groupadd -g $PGID docker-user && \
    useradd -u $PUID -g docker-user -m docker-user && \
    mkdir /home/docker-user/.composer

COPY container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer
RUN chown -R docker-user:docker-user /home/docker-user/.composer
USER docker-user
RUN composer global install

But when I try to build the image it ends with the following error:

Step 6 : COPY container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer
lstat container-files/home/docker-user/.composer/composer.json: no such file or directory

The file does exist on the host as per this output:

$ ls -la workspace/container-files/home/docker-user/.composer/
total 12
drwxrwxr-x 2 rperez rperez 4096 Oct  5 11:34 .
drwxrwxr-x 3 rperez rperez 4096 Oct  5 11:14 ..
-rw-rw-r-- 1 rperez rperez  208 Oct  5 11:20 composer.json

I have tried also this syntax:

COPY container-files /

But didn't work either. So I should ask: what's wrong? Why this keep failing once and once? What I am missing here?


Solution

  • The documentation addresses this with:

    By default the docker build command will look for a Dockerfile at the root of the build context. The -f, --file, option lets you specify the path to an alternative file to use instead. This is useful in cases where the same set of files are used for multiple builds. The path must be to a file within the build context. If a relative path is specified then it is interpreted as relative to the root of the context.

    In this case I think is

    COPY workspace/container-files/home/docker-user/.composer/composer.json /home/docker-user/.composer