问题描述
想象一个这样的项目文件夹:
Imagine a project folder like this:
- project_folder
- source_code_folder_1
- docker_volume_folder
- source_code_file_1
- Dockerfile
- docker -compose.yml
- .dockerignore
- project_folder
- source_code_folder_1
- docker_volume_folder
- source_code_file_1
- Dockerfile
- docker-compose.yml
- .dockerignore
现在,如果
-
Dockerfile
包含一条指令添加。 / code /
和 - ,如果
docker-compose.yml
文件配置了使用docker_volume_folder
在其卷映射中,
- the
Dockerfile
contains an instructionADD . /code/
, and - if the
docker-compose.yml
file configures a service that uses thedocker_volume_folder
in its volume mapping,
然后我可以添加<$ c
.dockerignore
文件中的$ c> docker_volume_folder ,以防止将卷文件夹复制到Docker容器添加。 / code /
dockerfile中的指令?can I then add the
docker_volume_folder
in the.dockerignore
file, to prevent that the volume folder is copied to the docker container by theADD . /code/
instruction in the dockerfile?我认为将docker volume文件夹添加到docker容器不仅无用,甚至可能很危险。但是,我想避免Docker Compose不想创建该卷,因为
.dockerignore
文件中已提及该卷。I think adding the docker volume folder to the docker container is not only useless, maybe it's even dangerous. However, I want to avoid that Docker Compose does not want to create the volume, since it is mentioned in the
.dockerignore
file.我在dockerignore中找不到有关卷的信息。
I can't find information about volumes in the dockerignore in the documentation.
推荐答案
您可以在.dockerignore文件中包含该目录,这只会影响
You can include the directory in your .dockerignore file, that only affects the build, not the later volume mounts.
您可能要在映像中包含目录的唯一原因是是否要使用命名空间的内容来初始化命名卷。图片。如果仅使用主机卷,则不会有问题。
The only reason you may want to include the directory inside your image is if you want named volumes to be initialized with the contents of the image. If you only use host volumes, this will not be an issue.
这篇关于.dockeringore文件可以包含卷文件夹吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!