0

I am trying to copy files from one folder to another folder after start:

  containers:
    - image: my-image
      name: app
      volumeMounts:
        - name: shared-files
          mountPath: /var/folder1
      lifecycle:
        postStart:
          exec:
            command: ["/bin/sh", "-c", "cp -r /temp/. /var/fodler1"]

But for some reason files are not copied. When I am executing directly in the pod this command

/bin/sh -c "cp -r /temp/. /var/fodler1"

everything works fine.

What I am doing wrong?

rholdberh
  • 475
  • 1
  • 5
  • 19
  • Do you see any error message in the logs with that command while starting the pod? – LionsDen Oct 01 '21 at 09:36
  • try executing command from inside a bash script. It should work. Sometimes, these command behave stragely due to different reasons. – Prateek Jain Oct 01 '21 at 09:51
  • Is `folder` spelled the same way in both places? Can you do this work in an entrypoint wrapper script in your image, or `COPY` the content into the image without using a volume mount at all? – David Maze Oct 01 '21 at 10:24
  • @DavidMaze yes in my code folder is spelled correctly, just make a typo here – rholdberh Oct 01 '21 at 11:39
  • Can you see anything in events when you `kubectl describe pod ` ? As you can read [here](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/#debugging-hook-handlers) if `PostStart` handler fails for some reason, it should be reflected in events. – mario Oct 01 '21 at 17:27
  • @mario nothing there :( – rholdberh Oct 04 '21 at 10:39
  • Might be a race condition between postStart lifecycle and when the volume is attached and available. Try putting a `sleep 10;` before `cp` – lance.johnsn Nov 18 '21 at 21:03

0 Answers0