首页 > 解决方案 > Azure DevOps + Docker:“apt-get”未被识别为内部或外部命令

问题描述

我是 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}

标签: dockerazure-devops

解决方案


检查管道并验证您正在运行的操作系统。如果它是 Windows 映像,apt-get将无法正常工作。更改您的管道以使用 Linux 机器。


推荐阅读