我有一个docker-compose设置,例如:
/
- sources/
- docker-compose.yml
- Dockerfile
- .dockerignore
- many more files
Dockerfile包含说明,包括源代码的COPY命令。
由于所有工具的不同,包括多个docker设置,我想通过将所有文件移动到一个文件夹来对其进行组织:
/
- sources/
- docker/
- many more files
或仅将docker-compose.yml文件保留在此文件夹之外:
/
- sources/
- docker/
- many more files
我想要这样做是因为:
目前,我遇到了一些有意义的问题,例如:
COPY failed: Forbidden path outside the build context: ../sources/
是否可以实现此设置?谢谢!
最佳答案
在Dockerfile内部,您无法访问构建上下文之外的文件。在您的情况下,构建上下文是包含Dockerfile的目录。
您可以在composefile中更改构建上下文。
下面是一个示例,其中composefile位于根目录,Dockerfile
位于docker
文件夹下:
version: '3'
services:
test:
build:
context: .
dockerfile: docker/Dockerfile
在这种情况下,应在
Dockerfile
内部相对于上下文设置文件路径。COPY sources sources
对于dockerignore :
如在.dockerignore文件的文档中指定的:
Before the docker CLI sends the context to the docker daemon, it looks for a file named .dockerignore in the root directory of the context
因此,您需要将dockerignore文件添加到上下文的根目录。
关于docker - 将Docker设置移至文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49318043/