简体   繁体   English

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

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

I am trying to install python and pip & Ansible using Dockerfile but I get this error我正在尝试使用 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

Here is my Dockerfile:这是我的 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

Note: I used the same instructions on another Dockerfile and it went without errors.注意:我在另一个 Dockerfile 上使用了相同的指令,并且没有错误。 Here is the Dockerfile from CentOS image:这是来自 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

SOLVED !!解决了 !!

I deleted RUN instructions and replaced it with:我删除了 RUN 指令并将其替换为:

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

Worked like a charm.像魅力一样工作。

Since I'm not entirely sure my comments were fully understandable, here is how I would install ansible in your current base image jenkins/jenkins .由于我不完全确定我的评论是否完全可以理解,因此我将在您当前的基础映像jenkins/jenkins ansible

Notes:笔记:

  • I fixed the tag to lts since building from latest is a bit on the edge.我将标签固定为lts ,因为从最新版本构建有点边缘。 You can change that to whatever tag suits your needs.您可以将其更改为适合您需要的任何标签。
  • I used two RUN directives (one for installing python, the other for ansible) but you can merge them in a single instruction if you want to further limit the number of layers.我使用了两个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