How to append an argument to a container command?

4/13/2017

I have node.js application built using Dockerfile that defines:

CMD node dist/bin/index.js

I'd like to "append" a parameter to the command as it is defined in Dockerfile, i.e. I want to execute the program as node dist/bin/index.js foo.

In docker land I am able to achieve this via:

docker build --tag test .
docker run test foo 

In kubernetes I cannot use command because that will override the ENTRYPOINT. I cannot use args because that will override the cmd defined in the Dockerfile. It appears that my only option is:

cmd: ["node", "dist/bin/index.js", "foo"]

Is there a way to append an argument to a container command without redefining the entire Docker CMD definition?

-- Gajus
docker
kubernetes

4 Answers

4/13/2017

I don't there is a way to achieve what you want, except for setting the cmd, as you mentioned.

-- Yu-Ju Hong
Source: StackOverflow

4/14/2017

Let me know if I misunderstood your question, but if you just want to pass a parameter to the POD you can run your command inside the entrypoint script and use an environment variable that you pass to the container for that command. This should work in any Pod spec (as part of the deployment description for example).

Example

apiVersion: v1
kind: Pod
metadata:
  name: envar-demo
  labels:
    purpose: demonstrate-envars
spec:
  containers:
  - name: envar-demo-container
    image: gcr.io/google-samples/node-hello:1.0
    env:
    - name: DEMO_GREETING
      value: "Hello from the environment"

For more see this doc.

-- Oswin Noetzelmann
Source: StackOverflow

4/14/2017

No way to append. You can either set the command: or args: on container.spec. You can learn more about how to override CMD/ENTRYPOINT here: https://kubernetes.io/docs/concepts/configuration/container-command-args/

-- AhmetB - Google
Source: StackOverflow

12/17/2019

You might be able to achieve the same effect using an optional param in your Dockerfile:

ENV YOUR_OPTIONAL_PARAM
CMD node dist/bin/index.js $YOUR_OPTIONAL_PARAM
-- Stefan
Source: StackOverflow