Kubernetes - Passing multiple commands to the container

前端 未结 3 1664
北海茫月
北海茫月 2020-12-24 06:55

I want send multiple entrypoint commands to a Docker container in the command tag of kubernetes config file.

apiVersion: v1
kind: Pod
metadata:
         


        
相关标签:
3条回答
  • 2020-12-24 07:00

    use this command

    command: ["/bin/sh","-c"]
    args: ["command one; command two && command three"]
    
    0 讨论(0)
  • 2020-12-24 07:08

    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).

    0 讨论(0)
  • 2020-12-24 07:15

    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 /"]

    0 讨论(0)
提交回复
热议问题