Docker-撰写未能读取 Docker 文件
Docker-compose failed to read Dockerfile
从昨天 (01.12.) 开始,我的 compose 遇到了一个奇怪的问题,我的 docker-compose 无法读取 Docker 文件。这个问题突然出现,因为代码没有改变,但构建开始失败。
我的docker-撰写:
service1:
image: service1-image
build:
context: ${SERVICE1_DIR}
dockerfile: \src\Service1.Service\Service1.Service.Web\Dockerfile-Development
ports:
- "${HTTP_SERVICE1_PORT}:80"
- "${HTTPS_SERVICE1_PORT}:443"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+;http://+
- ASPNETCORE_HTTPS_PORT=${HTTPS_SERVICE1_PORT}
- ASPNETCORE_ConnectionStrings__SQLServer=Server=sqlserver;Database=Service1;User ID=sa;Password=****
- ASPNETCORE_Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
- ASPNETCORE_Kestrel__Certificates__Default__Path=${SERVICE1_CERT_PATH}
volumes:
- ${DOCKER_DIR}\https:/https/:ro
Dockerfile-Development 本身没有问题,因为我可以使用 docker build 命令直接构建映像。另外,如果我将其更改为 Dockerfile,错误是相同的。
SERVICE1_DIR is the path to the root of the folder (solution) and then
I am extending the path to dockerfile which is located where my Web
API project is. There are a couple of Class Library project on which
my API has a dependency on. All of which I am referencing in my
dockerfile without any issue.
我的环境:
- docker-合成文件版本:3.4
- docker 版本:Docker 版本 20.10.11,build dea9396
我正在使用 .NET SDK 6.0 和 ASPNET 6.0 运行时。
这是错误:
=> ERROR [internal] load build definition from Dockerfile-Development
0.1s
=> => transferring dockerfile: 79B
0.0s
=> [internal] load .dockerignore
0.1s
=> => transferring context: 35B
0.0s
------
[internal] load build definition from Dockerfile-Development:
------
failed to solve with frontend dockerfile.v0: failed to read dockerfile: error from
sender: resolve : CreateFile \?\C:\src: The system cannot find the file specified.
ERROR: Service 'service1' failed to build : Build failed
** 更新解决方案 **
解决了在 build
中将路径的缺失部分添加到 dockerfile 的问题
工作docker-撰写文件:
service1:
image: service1-image
build:
context: ${SERVICE1_DIR}
dockerfile: ${SERVICE1_DIR}\src\Service1.Service\Service1.Service.Web\Dockerfile-Development
ports:
- "${HTTP_SERVICE1_PORT}:80"
- "${HTTPS_SERVICE1_PORT}:443"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+;http://+
- ASPNETCORE_HTTPS_PORT=${HTTPS_SERVICE1_PORT}
- ASPNETCORE_ConnectionStrings__SQLServer=Server=sqlserver;Database=Service1;User ID=sa;Password=****
- ASPNETCORE_Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
- ASPNETCORE_Kestrel__Certificates__Default__Path=${SERVICE1_CERT_PATH}
volumes:
- ${DOCKER_DIR}\https:/https/:ro
在你的 docker-compose.yaml 中你有 dockerfile
和 \src\Service1.Service\Service1.Service.Web\Dockerfile-Development
这是 Windows 解析为 C:\src...
的绝对路径.除非您的应用程序在此目录中,否则 docker-compose.yaml 中的 dockerfile
路径是不正确的,应该是相对于 docker-compose.yaml 的。可能 ${SERVICE1_DIR}\Service1.Service.Web\Dockerfile-Development
或类似。
从昨天 (01.12.) 开始,我的 compose 遇到了一个奇怪的问题,我的 docker-compose 无法读取 Docker 文件。这个问题突然出现,因为代码没有改变,但构建开始失败。
我的docker-撰写:
service1:
image: service1-image
build:
context: ${SERVICE1_DIR}
dockerfile: \src\Service1.Service\Service1.Service.Web\Dockerfile-Development
ports:
- "${HTTP_SERVICE1_PORT}:80"
- "${HTTPS_SERVICE1_PORT}:443"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+;http://+
- ASPNETCORE_HTTPS_PORT=${HTTPS_SERVICE1_PORT}
- ASPNETCORE_ConnectionStrings__SQLServer=Server=sqlserver;Database=Service1;User ID=sa;Password=****
- ASPNETCORE_Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
- ASPNETCORE_Kestrel__Certificates__Default__Path=${SERVICE1_CERT_PATH}
volumes:
- ${DOCKER_DIR}\https:/https/:ro
Dockerfile-Development 本身没有问题,因为我可以使用 docker build 命令直接构建映像。另外,如果我将其更改为 Dockerfile,错误是相同的。
SERVICE1_DIR is the path to the root of the folder (solution) and then I am extending the path to dockerfile which is located where my Web API project is. There are a couple of Class Library project on which my API has a dependency on. All of which I am referencing in my dockerfile without any issue.
我的环境:
- docker-合成文件版本:3.4
- docker 版本:Docker 版本 20.10.11,build dea9396
我正在使用 .NET SDK 6.0 和 ASPNET 6.0 运行时。
这是错误:
=> ERROR [internal] load build definition from Dockerfile-Development
0.1s
=> => transferring dockerfile: 79B
0.0s
=> [internal] load .dockerignore
0.1s
=> => transferring context: 35B
0.0s
------
[internal] load build definition from Dockerfile-Development:
------
failed to solve with frontend dockerfile.v0: failed to read dockerfile: error from
sender: resolve : CreateFile \?\C:\src: The system cannot find the file specified.
ERROR: Service 'service1' failed to build : Build failed
** 更新解决方案 **
解决了在 build
中将路径的缺失部分添加到 dockerfile 的问题工作docker-撰写文件:
service1:
image: service1-image
build:
context: ${SERVICE1_DIR}
dockerfile: ${SERVICE1_DIR}\src\Service1.Service\Service1.Service.Web\Dockerfile-Development
ports:
- "${HTTP_SERVICE1_PORT}:80"
- "${HTTPS_SERVICE1_PORT}:443"
environment:
- ASPNETCORE_ENVIRONMENT=Development
- ASPNETCORE_URLS=https://+;http://+
- ASPNETCORE_HTTPS_PORT=${HTTPS_SERVICE1_PORT}
- ASPNETCORE_ConnectionStrings__SQLServer=Server=sqlserver;Database=Service1;User ID=sa;Password=****
- ASPNETCORE_Kestrel__Certificates__Default__Password=${CERT_PASSWORD}
- ASPNETCORE_Kestrel__Certificates__Default__Path=${SERVICE1_CERT_PATH}
volumes:
- ${DOCKER_DIR}\https:/https/:ro
在你的 docker-compose.yaml 中你有 dockerfile
和 \src\Service1.Service\Service1.Service.Web\Dockerfile-Development
这是 Windows 解析为 C:\src...
的绝对路径.除非您的应用程序在此目录中,否则 docker-compose.yaml 中的 dockerfile
路径是不正确的,应该是相对于 docker-compose.yaml 的。可能 ${SERVICE1_DIR}\Service1.Service.Web\Dockerfile-Development
或类似。