简体   繁体   English

Docker 容器中的 Azure CLI

[英]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 blown away because Azure CLI requires older versions; 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 需要旧版本; then making it so I can't run my python scripts.然后使它无法运行我的 python 脚本。

I have tried to use the script installer but that hasn't worked and errored out because I believe the install is interactive.我曾尝试使用脚本安装程序,但由于我相信安装是交互式的,所以没有奏效并且出错了。

The last option I can find is the manual apt install , though I am not sure this is a correct way nor do I have a good idea of how to replicate that in a Dockerfile .我能找到的最后一个选项是手动 apt install ,尽管我不确定这是正确的方法,也不知道如何在Dockerfile中复制它。

Is there a preferred/good way of getting Azure CLI in a container not using pip ?在不使用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

I have a preference to use the package manager to install dependencies, it's why I will do something like that:我倾向于使用 package 管理器来安装依赖项,这就是为什么我会这样做:

  • Add base dependencies for https repostory and curl为 https 存储库和 curl 添加基本依赖项
  • Add the gpg key and repository for the CLI为 CLI 添加 gpg 密钥和存储库
  • Add the CLI添加命令行界面

This is the Dockerfile with thoses steps:这是带有这些步骤的 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/*

In addition, I clean up the apt cache by removing /var/lib/apt/lists .此外,我通过删除/var/lib/apt/lists来清理 apt 缓存。 Tt reduces the image size, since the apt cache is not stored in a layer. Tt 减小了图像大小,因为 apt 缓存没有存储在层中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM