Kubernetes - Passing multiple commands to the container
I want send multiple entrypoint commands to a Docker container in the command
tag of kubernetes config file.
apiVersion: v1
kind: Pod
metadata:
name: hello-world
spec: # specification of the pod’s contents
restartPolicy: Never
containers:
- name: hello
image: "ubuntu:14.04"
command: ["command1 arg1 arg2 && command2 arg3 && command3 arg 4"]
But it seems like it does not work. What is the correct format of sending multiple commands in the command tag?
Solution 1:
There can only be a single entrypoint in a container... if you want to run multiple commands like that, make bash be the entry point, and make all the other commands be an argument for bash to run:
command: ["/bin/bash","-c","touch /foo && echo 'here' && ls /"]
Solution 2:
Jordan's answer is correct.
But to improve readability I would prefer:
apiVersion: v1
kind: Pod
metadata:
name: hello-world
spec: # specification of the pod’s contents
restartPolicy: Never
containers:
- name: hello
image: "ubuntu:14.04"
command: ["/bin/sh"]
args:
- -c
- >-
command1 arg1 arg2 &&
command2 arg3 &&
command3 arg4
Read this to understand YAML block scalar (The above >-
format).
Solution 3:
use this command
command: ["/bin/sh","-c"]
args: ["command one; command two && command three"]