docker - 为什么找不到 chmod 和 doctl?
问题描述
我创建了一个包含以下内容的 docker 镜像:
FROM ubuntu:20.10
RUN apt-get update
RUN apt-get install -y curl
RUN apt-get install -y git
RUN curl -L https://github.com/digitalocean/doctl/releases/download/v1.43.0/doctl-1.43.0-linux-amd64.tar.gz | tar xz
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
RUN curl -L https://github.com/argoproj/argo-cd/releases/download/v1.5.5/argocd-linux-amd64 -o argocd
RUN curl -L https://get.helm.sh/helm-v3.2.1-linux-amd64.tar.gz | tar xz
RUN chmod +x ./argocd
RUN chmod +x ./kubectl
RUN chmod +x ./linux-amd64/helm
RUN mv ./argocd /usr/local/bin/
RUN mv ./kubectl /usr/local/bin/
RUN mv ./doctl /usr/local/bin/
RUN mv ./linux-amd64/helm /usr/local/bin/
WORKDIR /sh
COPY test.sh /sh
RUN chmod +x /sh/test.sh
然后我在我的计算机上本地测试了图像,如果图像有效:
docker pull hub.databaker.io/devops/argcd-cli:0.1.22
docker run -it --rm hub.databaker.io/devops/argcd-cli:0.1.22
root@76db905a83c6:/sh# pwd
/sh
root@76db905a83c6:/sh# doctl version
doctl version 1.43.0-release
Git commit hash: 1b6d0b8
如您所见,我可以doctl
在容器内调用它并显示预期结果。
我使用Drone CI构建管道并在以下管道上遇到问题:
kind: pipeline
type: docker
name: DEV build, push and deploy
steps:
- name: DEV deployment
image: hub.databaker.io/devops/argcd-cli:0.1.22
pull: if-not-exists
environment:
DO_AC:
from_secret: do_ac
K8S_CLUSTER:
from_secret: k8s_cluster
ARGO_SERVER:
from_secret: argo_server
ARGO_USERNAME:
from_secret: argo_username
ARGO_PW:
from_secret: argo_pw
IMAGE_VERSION: ${DRONE_SEMVER_SHORT}
USER:
from_secret: gituser
PW:
from_secret: gitpw
GIT_URL: gitlab.com/databaker.io/gitops.git
PATH: keycloak-svc
NAMESPACE: dev
commands:
- cd /sh
- pwd
- doctl version
trigger:
event:
- tag
image_pull_secrets:
- dockerconfig
它显示以下错误消息:
/bin/sh: 5: chmod: not found
/bin/sh: 24: doctl: not found
+ cd /sh
+ pwd
/sh
+ doctl version
我也试过:
commands:
- ls -la
- cd /usr/local/bin/
- ls -la
- /bin/bash -c doctl version
- /bin/bash -c pwd
- doctl version
并得到:
/bin/sh: 5: chmod: not found
2 /bin/sh: 18: ls: not found
3 + ls -la
为什么在管道doctl
中chmod
找不到?我是否忘记激活管道上的某些内容?
解决方案
PATH
在您的 Drone 环境变量中被覆盖
看起来您的PATH
变量并非旨在保存可执行路径(PATH: keycloak-svc
)。我建议使用不同的名称。
如果在更改该环境变量名称后,您发现它/usr/local/bin/
不在 Drone'sPATH
中,您可以将其添加到该commands
部分,如Drone 文档中所述。
笔记:
我想在找到其他人失败构建的PATH
日志后查看一下,然后查看他们大约在同一时间提交的更改。
推荐阅读
- kotlin - 有没有办法改变 IntelliJ Kotlin 编码风格以在函数之后或文件末尾捕获额外的空白?
- netbeans - 我如何知道软件是 64 位还是 32 位(x64 或 x32)
- c - 打印字符串的所有字符(包括转义序列)
- json - 子类化 JSON (Swift) 时出错
- vue.js - v-slot 的含义:activator="{ on }"
- python - 将 Pandas 2 个数据框合并为一张图
- c# - Bot Framework 简单切换场景
- docker - 无法在 docker 容器内执行二进制文件,但可以从主机执行
- c++ - 析构函数触发断点
- html - 将标签与输入类型文本对齐