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
I deleted RUN instructions and replaced it with :
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 imagejenkins/jenkins
.Notes:
lts
since building from latest is a bit on the edge. You can change that to whatever tag suits your needs.apt
and notyum/dnf
)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.