skip to Main Content

After Laravel Sail install, I published the Laravel Sail docker files to my project following the official docs. The directory is at {project root}/docker/8.1. This directory is also the one specified as build context in the docker-compose.yml file. I added a .dockerignore file in that directory with the following content:

**/.devcontainer
**/.git
**/.vscode
**/docker
[...]

When I terminal into the laravel container, the directories and files in my .dockerignore have been copied over despite [internal] load .dockerignore log statement on sail build. sail build is basically an alias for docker compose build.

How can I set-up my .dockerignore for it to be applied on container build?

As a side-note, I don’t really understand how the project source files are copied over to the container, as the Dockerfile does not seem to contain COPY or ADD instructions wrt these.

I have looked on this site for answers and on the web without success. I also went through the laravel/sail github issues.

Any input would be greatly appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    By default, the project files are copied over to the container using a volume. This is why the .dockerignore file is ignored. I decided to replace the volume by a COPY command in the Dockerfile:

    COPY --chown=$WWWUSER:$WWWGROUP . /var/www/html/
    

    I had to change the docker-compose.yml build directive as follow:

     build:
        context: .
        dockerfile: ./docker/8.1/Dockerfile
        args:
            WWWUSER: "${WWWUSER}"
            WWWGROUP: "${WWWGROUP}"
    

    I adjusted relative paths to local files in the Dockerfile.

    I placed the .dockerignore in the project root and it is now taken into account as expected.


  2. replace dockerfile: ./docker/8.1 with context: ./vendor/laravel/sail/runtimes/8.1 in the docker-compose.yml file

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search