简体   繁体   中英

getting a No such file or directory error with Kubernetes cronjob and dockerfile

I have a script that I want to run using a dockerfile that looks like this:

FROM debian:unstable-slim

RUN apt-get update && apt-get install -y netcat-traditional httpie postgresql-client

COPY go.sh /tmp/go.sh

WORKDIR /tmp
CMD ["bash", "-c", "/tmp/go.sh"]

It works fine on local, but I need to deploy it as a kubernetes cronjob, I have a config file with something like this:

script:
- docker build -t {github_enterprise_url/org/repo} .

And the build output seems ok:

...
Step 3/7 : COPY go.sh /tmp/go.sh
 ---> ab8d5227f65e
...
Successfully built e79162d90def

And for the cronjob yaml, among other things, I have something like this:

spec:
  containers:
    - image: >-
        ${ trigger.artifacts.?[type == 'docker'].?[name matches
        'org/repo'].![reference][0] }

the deploy then succeded but with this message:

Cannot determine if job needs to be started: Too many missed start time (> 100). Set or decrease .spec.startingDeadlineSeconds or check clock skew.

So I tried to run it manually like this:

kubectl create job --from=cronjob/name name-manual-123

And when looking at the logs for the pod created, I get this:

kubectl logs name-manual-123-ab1cd
bash: line 1: /tmp/go.sh: No such file or directory

any clue?

The /tmp directory is generally intended for temporary file storage. It's common to mount a RAM disk ( tmpfs ) there, and it's possible the Kubernetes setup does this without you noticing it.

You can address this by storing your script in a location that's on the default PATH , like /usr/local/bin :

# /usr/local/bin, not /tmp
COPY go.sh /usr/local/bin

CMD ["go.sh"]
# will work when the script is executable; on $PATH (in /usr/local/bin);
# and has a correct shebang line
# #!/bin/sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM