COPY a shell script file than RUN it occur not found error
The case is very very simple, and I can not figgure out how it happend. Does any method to bypass this problem?
Actual behavior
INFO[0000] Retrieving image manifest ubuntu:18.04
INFO[0000] Retrieving image ubuntu:18.04 from registry index.docker.io
INFO[0008] Built cross stage deps: map[]
INFO[0008] Retrieving image manifest ubuntu:18.04
INFO[0008] Returning cached image manifest
INFO[0008] Executing 0 build triggers
INFO[0008] Building stage 'ubuntu:18.04' [idx: '0', base-idx: '-1']
INFO[0008] Unpacking rootfs as cmd COPY build.sh /opt requires it.
INFO[0017] Initializing snapshotter ...
INFO[0017] Taking snapshot of full filesystem...
INFO[0017] COPY build.sh /opt
INFO[0017] RUN /opt/build.sh
INFO[0017] Cmd: /bin/sh
INFO[0017] Args: [-c /opt/build.sh]
INFO[0017] Running: [/bin/sh -c /opt/build.sh]
/bin/sh: 1: /opt/build.sh: not found
error building image: error building stage: failed to execute command: waiting for process to exit: exit status 127
Expected behavior
To Reproduce kubectl apply this YAML:
apiVersion: v1
kind: ConfigMap
metadata:
name: kaniko
data:
build.sh: 'ls / > /tmp/ls'
dockerfile: |
FROM ubuntu:18.04
COPY build.sh /opt
RUN /opt/build.sh
---
apiVersion: v1
kind: Pod
metadata:
name: kaniko
spec:
containers:
- name: kaniko
image: gcr.io/kaniko-project/executor
args:
- "--no-push"
volumeMounts:
- name: dockerfile
mountPath: /workspace
resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 100m
memory: 512Mi
restartPolicy: Never
volumes:
- name: dockerfile
configMap:
name: kaniko
items:
- key: dockerfile
path: Dockerfile
- key: build.sh
path: build.sh
mode: 0777
More than /opt, I've try /tmp / /app and still doesn't work
Additional Information
- Dockerfile see the ConfigMap in YAML
- Build Context see the ConfigMap in YAML
- Kaniko Image (fully qualified with digest)
66ecf6bdb0b6
Triage Notes for the Maintainers
| Description | Yes/No |
|---|---|
| Please check if this a new feature you are proposing |
|
| Please check if the build works in docker but not in kaniko |
|
Please check if this error is seen when you use --cache flag |
|
| Please check if your dockerfile is a multistage dockerfile |
|
Thanks for the issue @ealyn . It seems like from the logs that the volumeMounts for the shell script was not correctly mounted. Would you mind providing more details of the outputs from docker build?
Thanks for the issue @ealyn . It seems like from the logs that the volumeMounts for the shell script was not correctly mounted. Would you mind providing more details of the outputs from docker build?
If build.sh really not exist, it will raise error at COPY build.sh /opt.
bash /opt/build.sh is same with /opt/build.sh:
[+] Building 0.6s (8/8) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 102B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/ubuntu:18.04 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 27B 0.0s
=> [1/3] FROM docker.io/library/ubuntu:18.04 0.0s
=> [2/3] COPY build.sh /opt 0.0s
=> [3/3] RUN bash /opt/build.sh 0.3s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:242c77634a78208f9845adacc40736580af08ebe5b469a2145851fa976feb498 0.0s
=> => naming to docker.io/library/test
@aaron-prindle @JeromeJu please just find a GKE cluster to apply YAML I provided, it won't waste your time more than one minute.
Thanks @ealyn for the follwup. In that case is this issue similar with https://github.com/GoogleContainerTools/kaniko/issues/2721?
Thanks @ealyn for the follwup. In that case is this issue similar with #2721?
Yeah, only difference is my case have not symlink folder.
@JeromeJu After replace COPY build.sh /opt with COPY . /opt, it works fine !
@ealyn apologies for resurrecting an ancient thread, but maybe it helps others who stumble across this:
The problem you're facing in this example is that due to the way Kubernetes ConfigMaps work, your build.sh is after all a symlink (though not in the same way as in the other issue).
So when using COPY build.sh /opt the /opt directory looks like this, with build.sh pointing at a non-existent ..data directory:
INFO[0005] Running: [/bin/sh -c ls -lha /opt]
total 0 drwxr-xr-x 2 root root 22 Feb 13 11:01 . drwxr-xr-x 1 root root 191 Feb 13 11:01 ..
lrwxrwxrwx 1 root root 15 Feb 13 11:01 build.sh -> ..data/build.sh
But when using COPY . /opt it copies everything, including the ..data directory, so it works:
INFO[0005] Running: [/bin/sh -c ls -lha /opt]
total 0
drwxrwxrwx 3 root root 94 Feb 13 11:08 .
drwxr-xr-x 1 root root 191 Feb 13 11:08 ..
drwxr-xr-x 2 root root 40 Feb 13 11:08 ..2025_02_13_11_08_38.3016186420
lrwxrwxrwx 1 root root 32 Feb 13 11:08 ..data -> ..2025_02_13_11_08_38.3016186420
lrwxrwxrwx 1 root root 17 Feb 13 11:08 Dockerfile -> ..data/Dockerfile
lrwxrwxrwx 1 root root 15 Feb 13 11:08 build.sh -> ..data/build.sh
(so I think this issue can be closed)