Excluding folders mapped by volumes on app runinng on docker

84 Views Asked by At

Supposed I have a Docker container for running my app (let's say a Laravel app), so what I normally do is have the Dockerfile and the docker-compose.yml file under my root directory. So the folder structure would look something like this:

laravel_app/
- app/
- config/
- bootstrap/
etc etc
- public/
- node_modules/
- Dockerfile
- .dockerignore
- docker-compose.yml
- composer.json
- package.json

Now, in my docker-compose.yml file I would normally have the service for the app and the volumes mapping like this

version: "3"

services:
   app:
     image: ...
     container_name: ...
     build: ...
     ports: ...
     volumes:
        - .:/var/www/html

The problem is that if I ssh to the app container and list the content of my working dir with ls -la I can see that some folders that I have in my .dockerignore file, like for example the node_modules, are listed in the running container and I believe this is because volumes are mapping all the folders listed in my working directory locally (i.e. laravel_app).

So is there a way to specify in volumes to exclude the directories I don't wan't to be mapped or to read through all I've listed in my dockerignore file?

1

There are 1 best solutions below

0
KamilCuk On

So is there a way to specify in volumes to exclude the directories I don't wan't to be mapped or to read through all I've listed in my dockerignore file?

No, this is not possible.