0

I’m trying to build a Rails container, but exclude the “.bundle” directory when the volume is mounted. Locally I have this content

$ cat .bundle/config 
---
BUNDLE_JOBS: "4"
BUNDLE_BUILD__MYSQL2: "-- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

So in my docker-compose.yml file, I set it up like so

version: '3.3'
services:
…
  web:
    restart: "no"
    build: ../web
    ports:
      - "3000:3000"
    …
    volumes:
    - ../web/:/app
    - /app/.bundle/

However, when I rebuild all my containers (docker-compose down —rmi all) and then bring everything back up (docker-compose up), the file is appearing within my docker container

$ docker exec -it c363429babe4 bash
root@c363429babe4:/app# cat /app/.bundle/config 
---
BUNDLE_JOBS: "4"
BUNDLE_BUILD__MYSQL2: "-- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include"

What’s the proper way to exclude a directory when mounting a volume in Docker?

Dave
  • 15,639
  • 133
  • 442
  • 830
  • You can't "exclude a directory" when you mount(8) a filesystem over a directory in general in Linux; there's no special Docker feature that allows you to bypass this. – David Maze May 03 '22 at 05:02
  • What am I misinterpreting about this post -- https://stackoverflow.com/questions/29181032/add-a-volume-to-docker-but-exclude-a-sub-folder#:~:text=You%20can%20either%20use%20a,you%20run%20docker%20build%20from. ? They seem to imply you can do that – Dave May 03 '22 at 14:16
  • That setup copies the image's `node_modules` directory into an anonymous volume, then mounts the anonymous volume over the bind-mount directory over the image contents. It's a setup that means you can never update `package.json` without deleting the volume, and it's a setup that can lead to a "works only on my machine" setup because the anonymous volume has a different library tree. – David Maze May 03 '22 at 20:00
  • Imagine taking a screen shot of your IDE, printing it, and taping it on top of your monitor. So long as you haven't changed anything it's "correct", but even if you save the file you're working on and rebuild, you'll still see the printed-out copy first. – David Maze May 03 '22 at 20:02

1 Answers1

0

Delete the current Volumes on Docker, as they probably have cached the .bundle from your previous runs.

Your docker-compose file is correct as your override .bundle folder with an empty folder.