You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Alpine容器已装bash仍提示upload.sh未找到的问题咨询

Alpine容器执行bash脚本报错:/bin/sh: upload.sh: not found 排查与K8S配置疑问

报错信息:

/bin/sh: upload.sh: not found

Dockerfile内容

# bash on alpine

FROM quay.io/bashell/alpine:latest
WORKDIR /tmp

# make sure the package repository is up to date
RUN apk update \
 && apk upgrade \
 && apk add bash \
 && rm -rf /var/cache/*/* \
 && echo "" > /root/.ash_history

# change default shell from ash to bash
RUN sed -i -e "s/bin\/ash/bin\/bash/" /etc/passwd

ENV LC_ALL=en_US.UTF-8

# copy in upload.sh
COPY upload.sh .
RUN chmod +x upload.sh
RUN apk update && apk add curl git
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.15.1/bin/linux/amd64/kubectl
RUN chmod u+x kubectl && mv kubectl /bin/kubectl

upload.sh脚本内容

#!/bin/bash
touch myfile.txt
FILE=$(pwd)
echo "File is available at $FILE/myfile.txt

容器内/tmp目录ls -la输出

/tmp # ls -la
total 16
drwxrwxrwt    1 root     root          4096 Sep 19 14:40 .
drwxr-xr-x    1 root     root          4096 Sep 20 10:14 ..
-rwxr-xr-x    1 root     root            88 Sep 19 14:33 upload.sh

已尝试的排查操作

  • 进入容器确认bash路径为/bin/bash;
  • 检查upload.sh格式:换行符为LF,编码为UTF-8;
  • 脚本中改用#!/bin/sh(无论是否安装bash),仍报错;
  • 脚本中改用#!/bin/ash(无论是否安装bash),仍报错。

更新信息

进入容器执行sh upload.sh可成功运行脚本。

K8S部署配置疑问

实际场景是在K8S环境中运行该容器及脚本,部署配置如下,请问该配置是否正确?还是需要在构建Dockerfile时处理此问题?

apiVersion: v1
kind: Pod
metadata:
  name: alpine
  namespace: labs
spec:
  serviceAccountName: alpine
  containers:
  - image: myuser/alpine-kubectl
    volumeMounts:
            - name: datadir
              mountPath: /tmp
    command:
      - sh
      - "-c"
      - "./upload.sh && sleep 100000000"
    imagePullPolicy: IfNotPresent
    name: alpine
    
  restartPolicy: Always
  volumes:
        - name: datadir
          persistentVolumeClaim:
            claimName: alpine

内容的提问来源于stack exchange,提问作者Golide

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 23:10:56