docker - 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}
解决方案
检查管道并验证您正在运行的操作系统。如果它是 Windows 映像,apt-get
将无法正常工作。更改您的管道以使用 Linux 机器。
推荐阅读
- python - find_elements_by_ 之间的区别
和 WebDriverWait(self.driver, 20).until(EC.presence_of_element_located(locator) - mysql -
MySQL Errcode 28 - 设备上没有剩余空间 - html - hidden_field 值默认值被缓存值覆盖
- angular - 如何在 Ionic 的 5 离子输入上使用 MatAutocomplete?
- python - 系统找不到Python指定的文件
- javascript - 如何在 JS 中动态创建对象键?
- python-3.x - python 3使用AES加密和解密图像
- c++ - 如何使用 regex_search 获取报价中的内容
- python - 我怎么做才能让我的方格可以降落在我的另一个方格上并留在上面
- python - 使用 Python 更新 JSON 中的值