Search code examples
dockerdockerfilekubernetes-helmdocker-entrypoint

Overwrite entrypoint in Dockerfile without using the command "docker run"


I have a problem with overwriting the entrypoint in my Dockerfile. For this (as I know) docker run with --entrypoint option is used, e.g.:

docker run --entrypoint "python3 main_script.py DEV"

However, in my case I can't use the docker run command because I have to use Helm charts for the deployments.

Is there an alternative to docker run using Helm charts, or other alternatives/solutions that I may not have thought of?


Solution

  • use Helm charts for the deployments

    This is easy: Kubernetes command: overrides Docker ENTRYPOINT (and Kubernetes args: matches Docker CMD). So your Deployment spec can just say

    command:
      - python3
      - main_script.py
      - {{ .Values.environment }}
    

    Usually, though, you shouldn't need to override ENTRYPOINT, especially in a docker run context. An ENTRYPOINT isn't required, and it's very easy to override CMD at the end of the docker run line. So if you change your Dockerfile to say

    CMD python3 some_other_script.py
    # with no ENTRYPOINT
    

    then you can

    docker run my-image \
      python3 main_script.py DEV
    

    If that's not an option, then you need to be aware of the limitation that docker run --entrypoint only takes a single shell word. That means the first word of your command goes with --entrypoint and is a Docker option (before the image name), and the rest is interpreted as a command (after the image name).

    docker run \
      --entrypoint python3 \
      my-image \
      main_script.py DEV