【问题标题】:add-apt-repository fails during docker build在 docker build 期间 add-apt-repository 失败
【发布时间】:2018-01-05 10:59:52
【问题描述】:

我正在尝试启动并运行 dordoka/tomcat docker 映像,但在运行 docker build 时出现此错误:

Cannot add PPA: 'ppa:~webupd8team/ubuntu/y-ppa-manager'.
ERROR: '~webupd8team' user or team does not exist.
The command '/bin/sh -c apt-get update && 
apt-get install -y software-properties-common &&
add-apt-repository -y ppa:webupd8team/y-ppa-manager &&
add-apt-repository -y ppa:webupd8team/ubuntu/y-ppa-manager &&
apt-get update &&
apt-get install -y git build-essential curl wget software-properties-common'
returned a non-zero code: 1

失败的命令是add-apt-repository -y ppa:webupd8team/ubuntu/y-ppa-manager。此命令在 docker 之外运行良好。据我所知,代理配置正确。有什么想法吗?

【问题讨论】:

  • 我没问题,尝试从您的 dockerfile 中删除此命令,运行映像,然后在容器内运行命令。 docker exec -it [容器名称] /bin/bash
  • 我听从了@Kilian 的建议,并将问题缩小到代理。我什至无法使用curl 加载外部网页,所以add-apt-repository 不起作用也就不足为奇了。现在至少我知道如何进行了。
  • 问题是代理需要身份验证,但 root 没有获得 Kerberos 凭据。我在 Dockerfile 中将我的用户名和密码添加到 HTTPS_PROXY:ENV HTTPS_PROXY https://DOMAIN\USERNAME:PASSWORD@SERVER:PORT/ 进行此更改后,构建工作正常。有没有办法以 root 身份运行,以另一个用户身份进行身份验证,并且仍然避免使用硬编码的用户名和密码?
  • 您可以在 dockerfile 中创建环境变量,并在运行映像时使用 --env 注册您的用户/密码。不确定您的需求。 (对不起我的英语)

标签: docker apt docker-build


【解决方案1】:

@mlowry 您必须以 root 身份运行它有什么特别的原因吗?

我假设当您以用户身份运行它时,您还导出了 http_proxy ?

在这种情况下,您可以使用 --build-args 来传递 http_proxy 字符串。

快速示例:

ubuntu@ip-172-31-10-207:~/test$ docker build --build-arg http_proxy=$http_proxy .
Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM alpine:latest
 ---> e21c333399e0
Step 2/4 : ARG http_proxy
 ---> Running in fd0832692097
Removing intermediate container fd0832692097
 ---> 4c58ddefe37c
Step 3/4 : RUN export HTTP_PROXY=$http_proxy
 ---> Running in 913dc802ea8f
Removing intermediate container 913dc802ea8f
 ---> 9c3280343c13
Step 4/4 : RUN env
 ---> Running in 0d078193475a
HOSTNAME=0d078193475a
SHLVL=1
HOME=/root
http_proxy=http://domain\user:pass@proxy.com:8080
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
Removing intermediate container 0d078193475a
 ---> d4b8996fbb09
Successfully built d4b8996fbb09

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    • 1970-01-01
    • 2017-09-10
    • 2017-07-12
    相关资源
    最近更新 更多