docker - Azure DevOps + Docker : 'apt-get' is not recognized as an internal or external command

标签 docker azure-devops

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

相关文章:

android - 将 Android 依赖项添加到 Docker 构建镜像 - Bitbucket Pipelines (CI)

Docker rootfs_linux.go 挂载/proc 时权限被拒绝

git - 尝试对 Azure Devops 执行 git push 时登录失败

Azure devops 管道 : Cannot find Docker Image when Pushing to Azure Registry, 'tag ***/appname'

azure-devops - 仅在 ARM 模板部署后才知道 ConnectionString 时如何生成 EF Core 迁移脚本?

azure - 在 Azure 的云合作伙伴门户中禁用产品/服务的预览阶段

azure - VSTS 中输出下的应用程序服务 URL 的含义和作用是什么?

docker - 在Docker容器中启动服务

macos - 如何通过 SSH 连接到 Mac 容器中的 Docker

mysql - Docker 无法在 "localhost/subpage"上工作