Make docker-compose ignore folder within volume

2019-08-10 11:31发布

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?

3条回答
甜甜的少女心
2楼-- · 2019-08-10 12:02

What I ended up doing was to simply map all the folders which I wanted to sync:

- ./app:/app/app
- ./lib:/app/lib
- ./log:/app/log
- ./spec:/app/spec

Which seems to solve the problem

查看更多
Explosion°爆炸
3楼-- · 2019-08-10 12:05

You can use a data volume to store tmp, as data volumes copy in the data from the built docker image before the app directory is mounted

volumes:
- .:/app
- /path/to/tmp
查看更多
在下西门庆
4楼-- · 2019-08-10 12:13

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

查看更多
登录 后发表回答