docker 在构建容器时无法解析 DNS

docker 在构建容器时无法解析 DNS

我对此感到很困惑,我正在尝试为 m4b-tools 构建一个 docker 映像,并且我已遵循了所有说明。在安装过程进行到一半时,它决定无法解析 github.com。这是在安装了许多其他软件包之后。当我尝试从 busybox ping 时,到同一个域也运行正常。我进入 Dockerfile,提取命令并从命令行完美运行它们。因此主机可以正常解析,Docker 本身也可以正常解析,并且大概构建没有问题,因为我在网上看不到同样的问题。

我不知道为什么这会成为一个问题。这不是主机上的 DNS 问题,也不是 Docker 尝试 ping 时的问题,只是在使用 wget 构建此映像时才出现的问题。

我正在尝试在今天刚刚安装的最新版本的 Ubuntu 以及使用 WSL2 的 Docker 上运行它。

这是失败时的日志输出:

#8 33.10 Connecting to github.com (github.com)|140.82.121.4|:443... connected.
#8 33.16 HTTP request sent, awaiting response... 302 Found
#8 33.42 Location: https://codeload.github.com/sandreas/mp4v2/zip/master [following]
#8 33.42 --2021-08-23 16:39:14--  https://codeload.github.com/sandreas/mp4v2/zip/master
#8 33.42 Resolving codeload.github.com (codeload.github.com)... failed: Try again.
#8 38.43 wget: unable to resolve host address 'codeload.github.com'
------

这是 Dockerfile:

    ##############################
#
#   m4b-tool build image
#   alias m4b-tool='docker run -it --rm -u $(id -u):$(id -g) -v "$(pwd)":/mnt m4b-tool'
#   alias m4b-tool='docker run -it --entrypoint=m4b-tool-pre --rm -u $(id -u):$(id -g) -v "$(pwd)":/mnt m4b-tool'
##############################
FROM alpine:3.14 as builder

ARG FDK_AAC_VERSION=2.0.1
ARG FDK_AAC_URL="https://github.com/mstorsjo/fdk-aac/archive/v$FDK_AAC_VERSION.tar.gz"
ARG FDK_AAC_SHA256=a4142815d8d52d0e798212a5adea54ecf42bcd4eec8092b37a8cb615ace91dc6

RUN echo "---- INSTALL BUILD DEPENDENCIES ----" \
    && apk add --no-cache --update --upgrade --virtual=build-dependencies \
    autoconf \
    libtool \
    automake \
    boost-dev \
    build-base \
    gcc \
    git \
    tar \
    wget \
&& echo "---- COMPILE SANDREAS MP4V2 (for sort-title, sort-album and sort-author) ----" \
  && cd /tmp/ \
  && wget https://github.com/sandreas/mp4v2/archive/master.zip \
  && unzip master.zip \
  && cd mp4v2-master \
  && ./configure && \
  make -j4 && \
  make install && make distclean \
&& echo "---- PREPARE FDKAAC-DEPENDENCIES ----" \
  && cd /tmp/ \
  && wget -O fdk-aac.tar.gz "$FDK_AAC_URL" \
  && tar xfz fdk-aac.tar.gz \
  && cd fdk-aac-* && ./autogen.sh && ./configure --enable-static --disable-shared && make -j$(nproc) install \
&& echo "---- COMPILE FDKAAC ENCODER (executable binary for usage of --audio-profile) ----" \
    && cd /tmp/ \
    && wget https://github.com/nu774/fdkaac/archive/1.0.0.tar.gz \
    && tar xzf 1.0.0.tar.gz \
    && cd fdkaac-1.0.0 \
    && autoreconf -i && ./configure --enable-static --disable-shared && make -j4 && make install && rm -rf /tmp/* \
&& echo "---- REMOVE BUILD DEPENDENCIES (to keep image small) ----" \
    && apk del --purge build-dependencies && rm -rf /tmp/*

##############################
#
#   m4b-tool development image
#
##############################
FROM alpine:3.14
ENV WORKDIR /mnt/
ENV M4BTOOL_TMP_DIR /tmp/m4b-tool/


RUN echo "---- INSTALL RUNTIME PACKAGES ----" && \
  apk add --no-cache --update --upgrade \
  # mp4v2: required libraries
  libstdc++ \
  # m4b-tool: php cli, required extensions and php settings
  php7-cli \
  php7-dom \
  php7-json \
  php7-xml \
  php7-mbstring \
  php7-phar \
  php7-tokenizer \
  php7-xmlwriter \
  php7-openssl \
  && echo "date.timezone = UTC" >> /etc/php7/php.ini



# copy ffmpeg static with libfdk from mwader docker image
COPY --from=mwader/static-ffmpeg:4.4.0 /ffmpeg /usr/local/bin/

# copy compiled mp4v2 binaries, libs and fdkaac encoder to runtime image
COPY --from=builder /usr/local/bin/mp4* /usr/local/bin/fdkaac /usr/local/bin/
COPY --from=builder /usr/local/lib/libmp4v2* /usr/local/lib/


ARG M4B_TOOL_DOWNLOAD_LINK="https://github.com/sandreas/m4b-tool/releases/latest/download/m4b-tool.tar.gz"

# workaround to copy a local m4b-tool.phar IF it exists
ADD ./Dockerfile ./dist/m4b-tool.phar* /tmp/
RUN echo "---- INSTALL M4B-TOOL ----" \
    && if [ ! -f /tmp/m4b-tool.phar ]; then \
            wget "${M4B_TOOL_DOWNLOAD_LINK}" -O /tmp/m4b-tool.tar.gz && \
            if [ ! -f /tmp/m4b-tool.phar ]; then \
                tar xzf /tmp/m4b-tool.tar.gz -C /tmp/ && rm /tmp/m4b-tool.tar.gz ;\
            fi \
       fi \
    && mv /tmp/m4b-tool.phar /usr/local/bin/m4b-tool \
    && M4B_TOOL_PRE_RELEASE_LINK=$(wget -q -O - https://github.com/sandreas/m4b-tool/releases/tag/latest | grep -o 'M4B_TOOL_DOWNLOAD_LINK=[^ ]*' | head -1 | cut -d '=' -f 2) \
    && wget "${M4B_TOOL_PRE_RELEASE_LINK}" -O /tmp/m4b-tool.tar.gz \
    && tar xzf /tmp/m4b-tool.tar.gz -C /tmp/ && rm /tmp/m4b-tool.tar.gz \
    && mv /tmp/m4b-tool.phar /usr/local/bin/m4b-tool-pre \
    && chmod +x /usr/local/bin/m4b-tool /usr/local/bin/m4b-tool-pre
WORKDIR ${WORKDIR}
CMD ["list"]
ENTRYPOINT ["m4b-tool

答案1

好吧,这与 ipv6 有关。将 --inet4-only 添加到 wget 命令中有效

相关内容