[英]Azure CLI in a Docker Container
I have an Ubuntu 18.04 Docker image that I need Azure CLI installed in. For a Docker image, it seems the preferred way is to use pip
, however, I have other pip Azure libraries needed in the container that overlap with the CLI install and get被吹走了,因為 Azure CLI 需要舊版本; 然后使它無法運行我的 python 腳本。
我曾嘗試使用腳本安裝程序,但由於我相信安裝是交互式的,所以沒有奏效並且出錯了。
我能找到的最后一個選項是手動 apt install ,盡管我不確定這是正確的方法,也不知道如何在Dockerfile
中復制它。
在不使用pip
的容器中獲取 Azure CLI 是否有首選/好的方法?
FROM ubuntu:18.04
RUN apt-get update && apt-get -y upgrade && \
apt-get -f -y install curl python3-pip python-pip && \
pip3 install --upgrade pip && \
pip2 install --upgrade pip && \
pip3 install azure-storage-blob==12.3.0 & \\
pip3 install azure-cli
我傾向於使用 package 管理器來安裝依賴項,這就是為什么我會這樣做:
這是帶有這些步驟的 Dockerfile:
FROM ubuntu:18.04
RUN apt-get update && apt-get -y upgrade && \
apt-get -f -y install curl apt-transport-https lsb-release gnupg python3-pip python-pip && \
curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > /etc/apt/trusted.gpg.d/microsoft.asc.gpg && \
CLI_REPO=$(lsb_release -cs) && \
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ ${CLI_REPO} main" \
> /etc/apt/sources.list.d/azure-cli.list && \
apt-get update && \
apt-get install -y azure-cli && \
rm -rf /var/lib/apt/lists/*
此外,我通過刪除/var/lib/apt/lists
來清理 apt 緩存。 Tt 減小了圖像大小,因為 apt 緩存沒有存儲在層中。
RUN curl -LsS https://aka.ms/InstallAzureCLIDeb | bash && rm -rf /var/lib/apt/lists/*
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.