【问题标题】:How to install yq on Docker image python:3?如何在 Docker 镜像 python:3 上安装 yq?
【发布时间】:2021-06-28 08:00:27
【问题描述】:

我想做的事

我想安装 yq 来编辑 Docker 容器上的一些 yaml 文件。

Dockerfile

FROM python:3
RUN apt-get update

RUN apt-key adv --keyserver keyserver.ubuntu.com --keyserver-option http-proxy=http://xxxxxx.com:9999 --recv-keys CC86BB64
RUN apt-get install -y software-properties-common
RUN add-apt-repository ppa:rmescandon/yq
RUN apt update
RUN apt install yq -y

参考

https://github.com/mikefarah/yq#on-ubuntu-1604-or-higher-from-debian-package

构建日志

 => => transferring dockerfile: 486B                                                                                                                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                                                               0.0s
 => [internal] load metadata for docker.io/library/python:3                                                                                                                                                                                   0.0s
 => CACHED [1/7] FROM docker.io/library/python:3                                                                                                                                                                                              0.0s
 => [2/7] RUN apt-get update                                                                                                                                                                                                                  2.7s
 => [3/7] RUN apt-key adv --keyserver keyserver.ubuntu.com --keyserver-option http-proxy=http://xxxxxx.com:9999 --recv-keys CC86BB64                                                                                                   1.2s 
 => [4/7] RUN apt-get install -y software-properties-common                                                                                                                                                                                  11.4s 
 => [5/7] RUN add-apt-repository ppa:rmescandon/yq                                                                                                                                                                                           13.3s 
 => ERROR [6/7] RUN apt update                                                                                                                                                                                                                1.8s 
------                                                                                                                                                                                                                                             
 > [6/7] RUN apt update:                                                                                                                                                                                                                           
#9 0.159                                                                                                                                                                                                                                           
#9 0.159 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.                                                                                                                                                           
#9 0.159                                                                                                                                                                                                                                           
#9 0.205 Hit:1 http://deb.debian.org/debian buster InRelease                                                                                                                                                                                       
#9 0.205 Hit:2 http://security.debian.org/debian-security buster/updates InRelease
#9 0.227 Hit:3 http://deb.debian.org/debian buster-updates InRelease
#9 0.870 Ign:4 http://ppa.launchpad.net/rmescandon/yq/ubuntu impish InRelease
#9 1.356 Err:5 http://ppa.launchpad.net/rmescandon/yq/ubuntu impish Release
#9 1.356   404  Not Found [IP: 91.189.95.85 80]
#9 1.381 Reading package lists...
#9 1.752 E: The repository 'http://ppa.launchpad.net/rmescandon/yq/ubuntu impish Release' does not have a Release file.
------
executor failed running [/bin/sh -c apt update]: exit code: 100

问题

我该如何解决?

【问题讨论】:

  • --keyserver-option http-proxy 选项仅适用于我的环境。
  • 听起来您指向的 PPA 没有针对 python:3 基本映像使用的 Ubuntu 版本的构建。除了yq,你能写 Python 代码来操作 YAML 文件吗?
  • 是的,我可以使用 Python 操作 YAML 文件。

标签: docker debian yq


【解决方案1】:

TL;DR

yq 的 PPA 不适用于 python:3 映像的 Linux 发行版。
更改您的 Dockerfile 以直接下载二进制文件:

FROM python:3

RUN apt-get update
RUN apt-get install -y wget

# Latest on https://launchpad.net/~rmescandon/+archive/ubuntu/yq is 4.9.6
ARG VERSION=v4.9.6
ARG BINARY=yq_linux_386
RUN wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY} -O /usr/bin/yq \ 
    && chmod +x /usr/bin/yq

说明

提到的instructions for installing yq 期待基于 Ubuntu 的映像,但 python:3 Docker 映像基于 Debian 10 / Buster(截至撰写本答案时):

Dockerfile for python:3 = python:3.9 = python:3.9.6:

FROM buildpack-deps:buster
$ docker run -it python:3 bash
root@fa97b25dc0d3:/# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
root@fa97b25dc0d3:/# 

错误

E:存储库“http://ppa.launchpad.net/rmescandon/yq/ubuntu impish Release”没有发布文件。

表示包ppa:rmescandon/yqdoes not support your distribution。你可以从http://ppa.launchpad.net/rmescandon/yq/ubuntu查看支持分布:

解决方法是从源代码安装它或只下载yq 二进制文件本身。 yq支持这个:https://github.com/mikefarah/yq#wget:

wget

使用 wget 下载预编译的二进制文件:

通过 tar.gz 压缩

wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - | tar xz && mv ${BINARY} /usr/bin/yq

纯二进制

wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY} -O /usr/bin/yq && chmod +x /usr/bin/yq

例如,VERSION=v4.2.0 和 BINARY=yq_linux_amd64

yq's Releases page 中选择一个特定版本(最好匹配为 Ubuntu 分发的版本之一,与 PPA 中相同)并将您的 Dockerfile 修改为:

FROM python:3

RUN apt-get update
RUN apt-get install -y wget

# Latest on https://launchpad.net/~rmescandon/+archive/ubuntu/yq is 4.9.6
ARG VERSION=v4.9.6
ARG BINARY=yq_linux_386
RUN wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY} -O /usr/bin/yq \ 
    && chmod +x /usr/bin/yq

【讨论】:

    【解决方案2】:

    以前的答案对我来说不起作用。

    所以这是我的替代解决方案:

    从GitHub下载yq最新的可执行文件:

    RUN wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64
    

    设置文件的执行权限:

    RUN chmod a+x /usr/local/bin/yq
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-23
      • 2023-01-10
      • 2022-01-08
      • 2021-08-15
      • 2021-11-23
      • 2020-01-25
      • 2017-12-30
      • 2016-01-31
      相关资源
      最近更新 更多