0

I want to copy the contents of a parent directory (relative to the position of the Dockerfile) into my image.

This is the folder structure:

app-root/
  docker/
    php81aws/
      some-folder
      Dockerfile
      start-container
      supervisord.conf
  app_folders
  app_files

I'm calling docker build as follows:

app-root#> docker build -t laravel -f docker/php81aws/Dockerfile .

Or from docker compose with:

services: 
  laravel:
     build:
       context: ./
       dockerfile: docker/php81aws/Dockerfile

Therefore, the context should be in the app-root directory. In the dockerfile, I'm using COPY like so:

COPY docker/php81aws/start-container /usr/local/bin/start-container
COPY docker/php81aws/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN chmod +x /usr/local/bin/start-container

COPY --chown=www:www . /var/www/

It always gives me this error:

failed to compute cache key: "/start-container" not found: not found

I tried to use COPY ./docker/php81aws/start-container and COPY start-container but the error is always the same. Of course copying the parent directory also fails.

David Maze
  • 130,717
  • 29
  • 175
  • 215
Valentino
  • 465
  • 6
  • 17
  • That structure looks like it should work (I might move the Dockerfile up to the repository root to avoid the `docker build -f` option). Do you have a `.dockerignore` file that's causing files to be excluded from the build context? – David Maze Jul 19 '22 at 13:44
  • wow. That was it... I was excluding the docker folder. I didn't think it meant excluding it from the context! – Valentino Jul 19 '22 at 13:47
  • if you put this in an answer, I'll mark it as correct. Thank you! – Valentino Jul 19 '22 at 13:49

1 Answers1

1

You mention in a comment that your top-level app-root directory has a .dockerignore file that excludes the entire docker directory. While the Dockerfile will still be available, nothing else in that tree can be COPYed into the image, and if you COPY ./ ./ to copy the entire build context into the image, that directory won't be present.

Deleting this line from the .dockerignore file should fix your issue.

In general you want the .dockerignore file to include anything that's part of your host build-and-test environment, but should not by default be included in an image, possibly because the Dockerfile is going to rebuild it. In a Node context, for example, you almost always want to exclude the host's node_modules directory, or in a Java context often the Gradle build or Maven target directories. Anything you do want to include in the image needs to not be listed in .dockerignore.

David Maze
  • 130,717
  • 29
  • 175
  • 215