我是 Azure DevOps 的新手,正在尝试构建我的第一个完整管道,但在构建 Docker 镜像时遇到问题。
Docker 文件中的一行导致管道失败,即带有 apt-get 的一行!
你有办法解决这个问题吗?
这是我得到的错误(日志):
Step 11/25 : RUN apt-get update && apt-get install -y libgdiplus libc6-dev && dotnet dev-certs https; dotnet publish --self-contained --runtime linux-x64 -c Debug -o out src/${PROJECT};
---> Running in 29ada69fe569
'apt-get' is not recognized as an internal or external command,
operable program or batch file.
The command 'cmd /S /C apt-get update && apt-get install -y libgdiplus libc6-dev && dotnet dev-certs https; dotnet publish --self-contained --runtime linux-x64 -c Debug -o out src/${PROJECT};' returned a non-zero code: 1
'displayName:' is not recognized as an internal or external command,
operable program or batch file.
'failOnStderr:' is not recognized as an internal or external command,
operable program or batch file.
##[error]Cmd.exe exited with code '1'.
这是我的管道文件:
- script: |
docker image build --no-cache --tag=registry.gitlab.com/iznogood/myproject/iznogood.myproject.httpapi:1.0.0 -f .\src\Iznogood.Myproject\Dockerfile .
displayName: 'Build image'
failOnStderr: true
这是 Docker 文件:
### >>> GLOBALS
ARG ENVIRONMENT="Production"
ARG PROJECT="Iznogood.MyProject.HttpApi"
### <<<
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
### >>> IMPORTS
ARG ENVIRONMENT
ARG PROJECT
### <<<
ARG NUGET_CACHE=https://api.nuget.org/v3/index.json
ARG NUGET_FEED=https://api.nuget.org/v3/index.json
# Copy sources
COPY src/ /app/src
ADD common.props /app
WORKDIR /app
RUN apt-get update && apt-get install -y libgdiplus libc6-dev && dotnet dev-certs https; \
dotnet publish --self-contained --runtime linux-x64 -c Debug -o out src/${PROJECT};
# Start a new image from aspnet runtime image
#FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS runtime
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS runtime
### >>> IMPORTS
ARG ENVIRONMENT
ARG PROJECT
### <<<
ENV ASPNETCORE_ENVIRONMENT=${ENVIRONMENT}
ENV ASPNETCORE_URLS="http://+:80;https://+:443;https://+:44359"
#ENV ASPNETCORE_URLS="http://+:80"
ENV PROJECT="${PROJECT}.dll"
# Make logs a volume for persistence
VOLUME /app/Logs
# App directory
WORKDIR /app
# Copy our build from the previous stage in /app
COPY --from=build /app/out ./
RUN apt-get update && apt-get install -y ffmpeg libgdiplus libc6-dev
# Ports
EXPOSE 80
EXPOSE 443
EXPOSE 44359
ENTRYPOINT dotnet ${PROJECT}
最佳答案
检查管道并验证您正在运行的操作系统。如果它是 Windows 镜像,apt-get
将不起作用。更改您的管道以使用 Linux 机器。
关于docker - Azure DevOps + Docker : 'apt-get' is not recognized as an internal or external command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61418199/