RUN命令无法访问卷

时间:2017-12-23 22:31:18

标签: docker asp.net-web-api2 .net-core docker-compose dockerfile

RUN中显示的dockerfile无法看到ENTRYPOINT所在的卷目录。

以下是dockerfiledocker-compose.yml存在问题的示例:

FROM microsoft/dotnet:2.0-sdk
EXPOSE 5000
ENV ASPNETCORE_ENVIRONMENT=Development
WORKDIR /src/testing
RUN dotnet restore
ENTRYPOINT ["dotnet", "run", "--urls=http://0.0.0.0:5000"]

docker-compose.yml

version: "3.4"

services:
  doctnetcore-api-project:
    build: ./api/
    container_name: doctnetcore-api-project
    image: doctnetcore-api-project:development
    restart: 'always'
    networks:
      - mynetwork
    volumes:
      - /api/src:/src

networks:
  mywebmc:
    external:
      name: mynetwork

当我运行docker-compose up时,我收到如下错误:

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
ERROR: Service 'doctnetcore-api-project' failed to build: The command '/bin/sh -c dotnet restore' returned a non-zero code: 1

如果我在运行RUN dotnet restore之前注释掉dotnet restore并手动运行docker-compose,则可以正常使用。

因此无论出于何种原因,RUN无法看到我的卷目录,ENTRYPOINT可以看到我的卷目录。

1 个答案:

答案 0 :(得分:2)

Dockerfile中的语句在 build-time docker build)执行,此时没有卷存在。

相反,当您运行可以访问可能映射的卷的容器(ENTRYPOINT)时,会执行docker run