用.dockerignore忽略文件和目录
我有一个简单的.dockerignore
用以下内容:
.git/
.idea/
venv/
我的docker-compose.yml
文件安装卷:
version: "3"
services:
frontend:
build: .
command: ["gunicorn", "--bind", "0.0.0.0:8000", "project.app:create_app()"]
env_file:
- .env
volumes:
- .:/frontend
ports:
- "8000:8000"
也许我不了解<<<的完整语法或意图code> .dockerignore 文件,但是在运行docker-compose之后 - build
,.git/
,.idea/code>和
VENV/
最终进入我的容器。
我已经阅读并看到 this ,但似乎并不可行。一个人无法安装并防止文件和目录降落在容器中。
如何防止这些目录在容器中可用?
I have a simple .dockerignore
file with the following:
.git/
.idea/
venv/
My docker-compose.yml
file mounts the volume:
version: "3"
services:
frontend:
build: .
command: ["gunicorn", "--bind", "0.0.0.0:8000", "project.app:create_app()"]
env_file:
- .env
volumes:
- .:/frontend
ports:
- "8000:8000"
Perhaps I don't understand the full syntax or intent of the .dockerignore
file, but after running docker-compose up --build
, .git/
, .idea/
and venv/
end up in my container.
I've read up and saw this but it doesn't seem feasible that one cannot mount and prevent files and directories from landing in the container.
How do I prevent these directories from becoming available in the container?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
.dockerignore
文件将修改发送到Docker守护程序以构建图像的上下文。因此,除非您重新创建创建的图像,否则创建的图像将不会包含这些文件。音量安装座是完全分开的,主机音量安装座(又称绑定安装座)将直接将主机目录的内容直接映射到容器中。这是一个Linux OS级活动,不遵循
.dockerignore
。您需要将这些文件从安装到容器中的目录中排除,或者不将卷安装到容器中,并依靠图像来利用
.dockerignore
。The
.dockerignore
file will modify the context that is sent to the docker daemon to build the image. So the created image will not have these files inside unless you recreate them.The volume mount is completely separate and a host volume mount, aka bind mount, will map the contents of the host directory directly into the container as is. This is a Linux OS level activity that doesn't follow
.dockerignore
.You will need to exclude those files from the directory that you mount into the container, or not mount the volume into the container and rely on the image to take advantage of
.dockerignore
.