我正在嘗試使用 Dockerfile 安裝 python 和 pip & Ansible 但我收到此錯誤
/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
uj5u.com熱心網友回復:
由于我不完全確定我的評論是否完全可以理解,因此我將ansible在您當前的基本映像中進行安裝jenkins/jenkins。
筆記:
- 我將標簽固定為,
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
uj5u.com熱心網友回復:
我洗掉了 RUN 指令并將其替換為:
RUN apt-get update
RUN apt-get install -y ansible
像魅力一樣作業。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/407326.html
標籤:
