Kubernetes - 向容器传递多个命令

识趣 发表于: 2021-12-31   最后更新时间: 2021-12-31 23:38:22   852 游览

我想在 kubernetes 配置文件的命令标签中向 Docker 容器发送多个入口点命令。

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

但没有效果。发送多个命令的正确格式是什么?

发表于 2021-12-31

在一个容器中只能有一个入口,如果你想运行多个命令,让bash成为入口,并让所有其他命令成为bash运行的参数。

command: ["/bin/bash","-c","touch /foo && echo 'here' && ls /"]

为了提高可读性,我更喜欢:

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
你的答案

查看kubernetes相关的其他问题或提一个您自己的问题