首页 > 解决方案 > 无根 docker 导致“无法解析 github.com 的地址”

问题描述

在我的 dockerfile 中,我正在安装密码学 python 依赖项,但是当从无根 docker 构建轮子时,我收到以下错误:

...
generating cffi module 'build/temp.linux-x86_64-3.7/_openssl.c'
  running build_rust
      Updating crates.io index
  warning: spurious network error (2 tries remaining): failed to resolve address for github.com: Name does not resolve; class=Net (12)
  warning: spurious network error (1 tries remaining): failed to resolve address for github.com: Name does not resolve; class=Net (12)
  error: failed to get `pyo3` as a dependency of package `cryptography-rust v0.1.0 (/tmp/pip-install-h22hlaqn/cryptography_a2037904c10949639ccf8a3b2519f187/src/rust)`
  
  Caused by:
    failed to fetch `https://github.com/rust-lang/crates.io-index`
  
  Caused by:
    network failure seems to have happened
    if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
    https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
  
  Caused by:
    failed to resolve address for github.com: Name does not resolve; class=Net (12)
  
      =============================DEBUG ASSISTANCE=============================
      If you are seeing a compilation error please try the following steps to
      successfully install cryptography:
      1) Upgrade to the latest pip and try again. This will fix errors for most
         users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
      2) Read https://cryptography.io/en/latest/installation.html for specific
         instructions for your platform.
      3) Check our frequently asked questions for more information:
         https://cryptography.io/en/latest/faq.html
      4) Ensure you have a recent Rust toolchain installed:
         https://cryptography.io/en/latest/installation.html#rust
      5) If you are experiencing issues with Rust for *this release only* you may
         set the environment variable `CRYPTOGRAPHY_DONT_BUILD_RUST=1`.
      =============================DEBUG ASSISTANCE=============================
  

...

最奇怪的是,当从 root 用户构建时,相同的 dockerfile 编译绝对成功。我在arch linux上使用最新的docker版本,并在这里尝试了以下说明:https ://docs.docker.com/engine/security/rootless/并安装AUR,在这两种情况下都没有运气。那是我的码头文件:

FROM        python:3.7-alpine

ENV         LANG C.UTF-8

RUN         apk update \
            && apk add --virtual build-deps gcc g++ musl-dev python3 python3-dev autoconf automake linux-headers make libffi-dev openssl-dev \
            && apk add --no-cache bash postgresql-dev libxml2-dev libxslt-dev jpeg-dev zlib-dev freetype-dev lcms2-dev openjpeg-dev tiff-dev tk-dev tcl-dev git openssh-client rust cargo

RUN         mkdir -p /opt/carryall/app
RUN         mkdir -p /opt/carryall/static
RUN         mkdir -p /opt/carryall/media

WORKDIR     /opt/carryall/app

RUN         mkdir /root/.ssh/
ADD         id_rsa /root/.ssh/id_rsa_temp
RUN         cat /root/.ssh/id_rsa_temp | tr -d '\r' > /root/.ssh/id_rsa
RUN         chmod 400 /root/.ssh/id_rsa
RUN         touch /root/.ssh/known_hosts
RUN         ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts

ADD         requirements.txt /opt/carryall/app/
RUN         pip install --no-cache-dir -r /opt/carryall/app/requirements.txt

RUN         apk del --purge build-deps \
            && rm -rf /root/.cache /tmp/*

ADD         . /opt/carryall/app

标签: linuxdockerrustrust-cargo

解决方案


推荐阅读