簡體   English   中英

Can't install pip and python & ansible using Dockerfile in CentOS

[英]Can't install pip and python & ansible using Dockerfile in CentOS

我正在嘗試使用 Z3254677A7917C6C01F55212F86C57

/bin/sh: 1: python: not found
The command '/bin/sh -c curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py &&     python get-pip.py &&     python -m pip install --upgrade "pip < 21.0" &&     pip install ansible --upgrade' returned a non-zero code: 127
ERROR: Service 'jenkins' failed to build : Build failed

這是我的 Dockerfile:

FROM jenkins/jenkins

USER root



RUN curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py && \
    python get-pip.py && \
    python -m pip install --upgrade "pip < 21.0" && \
    pip install ansible --upgrade





USER jenkins

注意:我在另一個 Dockerfile 上使用了相同的指令,並且沒有錯誤。 這是來自 CentOS 圖像的 Dockerfile:

FROM centos:7

RUN yum update -y && \
    yum -y install openssh-server && \
    yum install -y passwd

RUN useradd remote_user && \
    echo "password" | passwd remote_user  --stdin && \
    mkdir /home/remote_user/.ssh && \
    chmod 700 /home/remote_user/.ssh

COPY remote-key.pub /home/remote_user/.ssh/authorized_keys

RUN chown remote_user:remote_user   -R /home/remote_user && \
    chmod 600 /home/remote_user/.ssh/authorized_keys

RUN /usr/sbin/sshd-keygen

RUN yum -y install mysql

RUN curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py && \
    python get-pip.py && \
    python -m pip install --upgrade "pip < 21.0" && \
    pip install awscli --upgrade

CMD /usr/sbin/sshd -D

解決了 !!

我刪除了 RUN 指令並將其替換為:

RUN apt-get update
RUN apt-get install -y ansible

像魅力一樣工作。

由於我不完全確定我的評論是否完全可以理解,因此我將在您當前的基礎映像jenkins/jenkins ansible

筆記:

  • 我將標簽固定為lts ,因為從最新版本構建有點邊緣。 您可以將其更改為適合您需要的任何標簽。
  • 我使用了兩個RUN指令(一個用於安裝 python,另一個用於 ansible),但如果您想進一步限制層數,可以將它們合並到一條指令中。
FROM jenkins/jenkins:lts

USER root

RUN apt-get update &&\
    apt-get install -y python3-pip &&\
    rm -rf /var/lib/apt/lists/*

RUN pip install --upgrade pip &&\
    pip install ansible &&\
    pip cache purge

USER jenkins

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM