1

I want to execute script before I run my container

If I execute script in container like that

      containers:
        - name: myservice
          image: myservice.azurecr.io/myservice:1.0.6019912
          volumeMounts:
          - name: secrets-store-inline
            mountPath: "/mnt/secrets-store"
            readOnly: true
          command:
            - '/bin/bash'
            - '-c'
            - 'ls /mnt/secrets-store;'

then that command replaces my entrypoint and the pod exits. How can I execute command but then start the container after that

1 Answer 1

5

A common way to do this is too use Init Containers but I'm unsure what you're trying to run before you run the ENTRYPOINT.

You can apply the same volume mounts in the init container(s), if the init work requires changing state of the mounted file system content.

Another solution may be to run the ENTRYPOINT's command as the last statement in the script.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for answering DazWilkin! How can I find what is the exact ENTRYPOINT command? Isn't it inside the Docker file? How to call docker? What is the command or how to find it?
Perhaps I can add the command to Docker instead! Instead of kubernetes, thanks!
You can docker inspect [[IMAGE]]:[[TAG]] to see the commands (layers) in an image. However, it sounds as though you did not create the image and then (!?) you should probably not change the image ("you break it, you pay for it") and would be better either using an init container or scripting running the image.
Thanks Daz, that helped me find the command! The Dockefile idea was not a very smart one though, because I need to run not during build but during run Thanks you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.