I am facing an error when attempting to run a bash script inside an alpine container :
/bin/sh: upload.sh: not found
This is happening despite that I have already installed bash as in the Dockerfile below :
# 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
The script upload.sh :
#!/bin/bash
touch myfile.txt
FILE=$(pwd)
echo "File is available at $FILE/myfile.txt
"
Output of 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
What I have tried :
Run and exec into the container
/tmp # which bash /bin/bash
Checked the formatting for upload.sh
Line endings is correct - LF
Encoding is correct - UTF-8
Tried using /bin/sh in the script (without and with bash installed) - still getting the same error
Tried using /bin/ash in the script (without and with bash installed) - still getting the same error
UPDATE:
I have found that when I exec into the container and run the script as :
sh upload
it executes successfully.
The actual use-case is to run the Docker container (and hence the script) in a K8S environment with the following deployment configuration (Is this correct?) :
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
Is this correct or I should handle the issue at the time I build the Dockerfile?