skip to Main Content

I am trying to install python and pip & Ansible using Dockerfile but I get this error

/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:

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. Here is the Dockerfile from CentOS image:

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

2

Answers


  1. Chosen as BEST ANSWER

    I deleted RUN instructions and replaced it with :

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

    Worked like a charm.


  2. 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.

    Notes:

    • I fixed the tag to lts since building from latest is a bit on the edge. You can change that to whatever tag suits your needs.
    • That base image is itself based on Ubuntu and not CentOS as reported in your title (hence using apt and not yum/dnf)
    • 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.
    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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search