[英]Setting context in docker-compose file for a parent folder
This is a follow up question to this question:这是这个问题的后续问题:
docker-compose - ADD failed: Forbidden path outside the build context docker-compose - 添加失败:构建上下文之外的禁止路径
I got a docker-compose file in which I want to set a context and docker file to look something like this:我有一个 docker-compose 文件,我想在其中设置一个上下文和 docker 文件,看起来像这样:
build:
context: <path to context>
dockerfile: <path to dockerfile>
For now my file is in the root folder so its simply:现在我的文件在根文件夹中,所以它很简单:
build:
context: .
dockerfile: .
This way it does work.这种方式确实有效。
The structure of the project is something like this:项目的结构是这样的:
./
- folder1/
- folder2/
docker-compose.yaml
DockerFile
I want to copy files as part of the commands in the DockerFile and I want the paths to be relative to the root folder of the project.我想复制文件作为 DockerFile 中命令的一部分,并且我希望路径相对于项目的根文件夹。
How with this project structure do I set the context to be the root folder of the project?如何使用此项目结构将上下文设置为项目的根文件夹? I tried doing context: ../../
but I then got an error:我尝试做context: ../../
但我得到了一个错误:
Error response from daemon: unexpected error reading Dockerfile: read (path): is a directory来自守护进程的错误响应:意外错误读取 Dockerfile:读取(路径):是一个目录
How do I set the context correctly?如何正确设置上下文?
You cannot change the context to be a parent folder, you can read it about it in the docker-compose documentation.您不能将上下文更改为父文件夹,您可以在 docker-compose 文档中阅读它。 https://docs.docker.com/compose/compose-file/compose-file-v3/#context https://docs.docker.com/compose/compose-file/compose-file-v3/#context
what you can do is have the composefile in the folder which in the the highest hierarchy and change the context accordingly.您可以做的是将 composefile 放在最高层次结构中的文件夹中,并相应地更改上下文。 like so:像这样:
version: "3.7"
services:
srv2:
build:
dockerfile: src/services/srv2/Dockerfile
context: ./
image: srv2
srv1:
build:
dockerfile: src/services/srv1/Dockerfile
context: ./
image: srv1
or you can make the context the directory of the service that contains the Dockerfile of the service或者您可以使上下文成为包含服务的 Dockerfile 的服务目录
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.