Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append an argument to a container command?

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?

like image 335
Gajus Avatar asked Apr 13 '17 15:04

Gajus


People also ask

Can we pass arguments to Docker container?

When we launch our Docker container, we can pass environment variables as key-value pairs directly into the command line using the parameter –env (or its short form -e). As can be seen, the Docker container correctly interprets the variable VARIABLE1.

Can we use CMD and ENTRYPOINT together?

There are many situations in which combining CMD and ENTRYPOINT would be the best solution for your Docker container. In such cases, the executable is defined with ENTRYPOINT, while CMD specifies the default parameter. Note: If you are using both instructions, make sure to keep them in exec form.

What happens when you press Ctrl P Q inside the container?

Note that pressing `Ctrl+C` when the terminal is attached to a container output causes the container to shut down. Use `Ctrl+PQ` in order to detach the terminal from container output.


1 Answers

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/

like image 168
ahmet alp balkan Avatar answered Oct 13 '22 01:10

ahmet alp balkan