I'm using docker-compose for a Rails setup. To sync the files, I've mounted the directory like (some of the code is omitted):
app:
build: .
command: rails server -p 3000 -b '0.0.0.0'
volumes:
- .:/app
However, when running the app, I don't want the folder, tmp, to be synced. Adding the folder to dockerignore only solves the problem when building the docker image. How can I ignore the tmp folder from being synced between the host and guest when running docker compose?
You can add a second volume to a sub-path. It will override the contents of the existing volume. Like so :
app:
build: .
command: rails server -p 3000 -b '0.0.0.0'
volumes:
- .:/app
- ./empty-tmp:/app/tmp
This will effectively make /app/tmp
show the contents of ./empty-tmp
on the host system. Instead of showing the contents of ./tmp
This used to be possible as described in Add a volume to Docker, but exclude a sub-folder. The solutions offered there didn't work for me anymore with docker-compose 1.25.0-rc3, file syntax v3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With