【发布时间】:2020-01-17 18:58:20
【问题描述】:
我正在使用 Docker Compose 文件来运行两个 Docker 容器,一个是我已经发布的映像,一个是构建。当我转到配置的位置时,我看不到图像。
Docker 编写
version: '3.4'
services:
twslogging:
image: ${DOCKER_REGISTRY-}twslogging
build:
context: .
dockerfile: twsLogging\Dockerfile
ports:
- '8000:8000'
twsUsers:
image: tbennet/twsusers
ports:
- '7000:7000'
DockerFile Loggin(一个内置的Docker组成)
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 8000
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1803 AS build
WORKDIR /src
COPY ["twsLogging/twsLogging.csproj", "twsLogging/"]
RUN dotnet restore "twsLogging/twsLogging.csproj"
COPY . .
WORKDIR "/src/twsLogging"
RUN dotnet build "twsLogging.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "twsLogging.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "twsLogging.dll"]
DockerFile(发布的用户 Docker 文件)
FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-nanoserver-1803 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
EXPOSE 7000
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-nanoserver-1803 AS build
WORKDIR /src
COPY twsUsers/nuget.config ./
COPY ["twsUsers/twsUsers.csproj", "twsUsers/"]
COPY ["twsDatabase/twsDatabase.csproj", "twsDatabase/"]
COPY . .
RUN dotnet restore "twsUsers/twsUsers.csproj" --configfile ./nuget.config
WORKDIR "/src/twsUsers"
RUN dotnet build "twsUsers.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "twsUsers.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "twsUsers.dll"]
【问题讨论】:
-
你说在配置的位置看不到图像是什么意思?您能与我们分享错误吗?此外,您不应该同时拥有
image和build用于单一服务。它应该是其中之一。我假设你想构建twslogging。 -
twsLogging 有效,但 twsUsers 无效
-
你的错误是什么?当我尝试
docker pull时,它似乎是一个私人注册表。 -
我刚刚添加了图片。它是一个私有存储库。在邮递员中我得到无法得到任何回应
-
您确定您的应用程序在容器内的 7000 端口上运行吗?您可以通过登录到正在运行的容器并卷曲您在邮递员中尝试的相同 url 进行测试(使用 localhost 和相同的端口,所以应该没问题)。如果您在容器内也没有得到任何响应,请仔细检查您的应用程序正在运行的端口。注意:在 Dockerfile 中暴露端口 7000 并没有多大作用,对于使用该图像的人来说,这是更多信息。
标签: c# .net docker asp.net-core .net-core