Home > Software engineering >  Package installed in dockerfile inaccessable in manifest file
Package installed in dockerfile inaccessable in manifest file

Time:12-13

I'm quite new to kubernetes and docker. I am trying to create a kubernetes CronJob which will, every x minutes, clone a repo, build the docker file in that repo, then apply the manifest file to create the job.

When I install git in the CronJob dockerfile, when I run any git command in the kubernetes manifest file, it doesn't recognise it. How should I go about fixing this please?

FROM python:3.8.10

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y git

RUN useradd -rm -d /home/worker -s /bin/bash -g root -G sudo -u 1001 worker
WORKDIR /home/worker
COPY . /home/worker

RUN chown -R 1001:1001 .

USER worker
ENTRYPOINT ["/bin/bash"]
apiVersion: "batch/v1"
kind: CronJob
metadata:
  name: cron-job-test
  namespace: me
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: hello
              image: busybox:1.28
              imagePullPolicy: Always
              command:
                - /bin/sh
                - -c
              args:
                - git log;
          restartPolicy: OnFailure

CodePudding user response:

You should use the correct image that has git binary installed to run git commands. In the manifest you are using image: busybox:1.28 to run the pod which doesnt have git installed. Hence you are getting the error.

Use correct image name and try

  • Related