无法在dockerfile中安装iputils和net-tools

时间:2020-05-07 17:55:20

标签: docker

我正在尝试在docker容器上安装ping和ifconfig。但是,当我运行此dockerfile时,出现以下错误:

E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libc/libcap2/libcap2_2.25-1.2_amd64.deb  Could not connect to archive.ubuntu.com:80 (91.189.88.142). - connect (111: Connection refused) Could not connect to archive.ubuntu.com:80 (91.189.88.152). - connect (111: Connection refused)
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libi/libidn/libidn11_1.33-2.1ubuntu1.2_amd64.deb  Unable to connect to archive.ubuntu.com:http:
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/i/iputils/iputils-ping_20161105-1ubuntu3_amd64.deb  Unable to connect to archive.ubuntu.com:http:
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libc/libcap2/libcap2-bin_2.25-1.2_amd64.deb  Unable to connect to archive.ubuntu.com:http:
E: Failed to fetch http://archive.ubuntu.com/ubuntu/pool/main/libc/libcap2/libpam-cap_2.25-1.2_amd64.deb  Unable to connect to archive.ubuntu.com:http:
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
The command '/bin/sh -c apt-get update && apt-get install -y iputils-ping' returned a non-zero code: 100

这是我用来构建映像的Dockerfile:

FROM openanalytics/r-base

# system libraries of general use
RUN apt-get update && apt-get install -y \
    sudo \
    libcairo2-dev \
    libxt-dev \
    libcurl4-gnutls-dev \
    libssl-dev \
    libssh2-1-dev \
    libssl1.0.0 
# system libraries RODBC
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    unixodbc \
    unixodbc-dev \
    unixodbc \
    unixodbc-dev \
    r-cran-rodbc \
    apt-transport-https \
    libssl-dev \
    libsasl2-dev \
    openssl \
    curl \
    unixodbc \
    gnupg \
    libc6 libc6-dev libc6-dbg
#.
# mssql drivers
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
#RUN curl https://packages.microsoft.com/config/ubuntu/19.10/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get update
RUN ACCEPT_EULA=Y apt-get install msodbcsql17
# optional: for bcp and sqlcmd
RUN ACCEPT_EULA=Y apt-get install mssql-tools
RUN ACCEPT_EULA=Y apt-get install -y msodbcsql17 unixodbc-dev mssql-tools
#iptools (ping, ifconfig)
RUN apt-get update && apt-get install -y iputils-ping
RUN apt-get install net-tools

安装iputils-ping和net-tools的命令是否错误?如果我注释掉iputils行并且仅单独安装Net-tools,则会收到类似的错误。

1 个答案:

答案 0 :(得分:1)

由于此行RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list > /etc/apt/sources.list.d/mssql-release.list

,此操作失败

您要使用Microsoft源代码替换整个文件,>运算符将替换文件,您需要使用>>附加到文件,因此将命令更改为RUN curl https://packages.microsoft.com/config/ubuntu/18.04/prod.list >> /etc/apt/sources.list.d/mssql-release.list

>>附加到文件或创建文件(如果文件不存在)。 >覆盖文件(如果存在)或创建文件(如果不存在)。

这就是为什么它找不到软件包。源被上一条命令删除。

此外,您只需在添加新资源后一次执行apt-get更新。

并且您在安装ping的命令中缺少-y

正确的命令:

RUN apt-get install net-tools -y

希望这会有所帮助。评论是否需要其他帮助。