使docker-compose忽略卷中的文件夹 [英] Make docker-compose ignore folder within volume

查看:153
本文介绍了使docker-compose忽略卷中的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker-compose进行Rails设置。为了同步文件,我已经安装了目录,例如(省略了一些代码):

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

但是,在运行应用程序时,我不希望文件夹tmp同步。
将文件夹添加到dockerignore仅解决构建docker映像时的问题。
运行docker compose时,如何在主机和来宾之间不同步tmp文件夹?

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

这将有效地使 / app / tmp 显示主机系统上 ./ empty-tmp 的内容。而不是显示 ./ tmp

This will effectively make /app/tmp show the contents of ./empty-tmp on the host system. Instead of showing the contents of ./tmp

这篇关于使docker-compose忽略卷中的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆