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
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 aCOPY
command in theDockerfile
:I had to change the
docker-compose.yml
build
directive as follow: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.replace
dockerfile: ./docker/8.1
withcontext: ./vendor/laravel/sail/runtimes/8.1
in thedocker-compose.yml
file