【问题标题】:sh: 1: ping: not found when running job from jenkinssh:1:ping:从詹金斯运行作业时找不到
【发布时间】:2021-07-04 05:39:37
【问题描述】:

我有一个 python 脚本,其中执行了各种 ping 检查。相同的 py 文件在本地触发时运行完美,但是当我在构建 docker 映像后从 jenkins 运行作业时,出现以下错误并且 ping 检查总是返回 false。

sh: 1: ping: 未找到

谁能帮我解释一下为什么会出现这个错误,我需要更新 dockerfile 并进行一些更新还是需要一些 jenkins 配置。

更新 docker 文件

FROM ubuntu:18.04

ADD requirements.txt /requirements.txt
ADD jenkins_bot.py /jenkins_bot.py
ADD src /src
ADD config /config
ADD run_unit_tests.sh /run_unit_tests.sh
ADD utests /utests

WORKDIR /

RUN DEBIAN_FRONTEND=noninteractive && apt-get -qq update && \
    apt-get -y install apt-utils && \
    apt-get -qqy install ssh && \
    apt-get -qqy install build-essential \
    python3-dev \
    python3-setuptools \
    libfreetype6-dev \
    libxft-dev && \
    apt-get -qqy install python3-pip && \
    pip3 install -r /requirements.txt
#RUN sh run_unit_tests.sh

提前致谢。

【问题讨论】:

  • 嗨,Barsha,请向我们提供您的 DockerFile
  • 更有可能是因为 docker 无法访问网络来 ping 目标,您是否将 docker 连接到网络(连接 && 移植容器和 PC 的方式以及 EXPOSE ing DockerFile 中的端口?Networking in Docker
  • @itshosyn 感谢您的建议,我已经更新了 Dockerfile。
  • apt-get install -y iputils-ping

标签: python docker jenkins containers


【解决方案1】:

ubuntu 基础映像中缺少 Ping。您可以按如下方式更新您的 dockerfile 来安装它:

FROM ubuntu:18.04

ADD requirements.txt /requirements.txt
ADD jenkins_bot.py /jenkins_bot.py
ADD src /src
ADD config /config
ADD run_unit_tests.sh /run_unit_tests.sh
ADD utests /utests

WORKDIR /

RUN DEBIAN_FRONTEND=noninteractive && apt-get -qq update && \
    apt-get -y install apt-utils && \
    apt-get install -y iputils-ping && \
    apt-get -qqy install ssh && \
    apt-get -qqy install build-essential \
    python3-dev \
    python3-setuptools \
    libfreetype6-dev \
    libxft-dev && \
    apt-get -qqy install python3-pip && \
    pip3 install -r /requirements.txt
#RUN sh run_unit_tests.sh

【讨论】:

    猜你喜欢
    • 2012-09-12
    • 1970-01-01
    • 2014-08-27
    • 1970-01-01
    • 2012-09-30
    • 2014-07-24
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多