command、args的区别
# command、args两项实现覆盖Dockerfile中ENTRYPOINT的功能,具体的command命令代替ENTRYPOINT的命令行,args代表集体的参数。
# 以下是使用场景
1. 如果command和args均没有指定,那么则使用Dockerfile的配置。
2. 如果command没有指定,但指定了args,那么Dockerfile中配置的ENTRYPOINT的命令行会被执行,并且将args中填写的参数追加到ENTRYPOINT中。
3. 如果command指定了,但args没有写,那么Dockerfile默认的配置会被忽略,执行输入的command(不带任何参数,当然command中可自带参数)。
4. 如果command和args都指定了,那么Dockerfile的配置被忽略,执行command并追加上args参数。
[root@Master ~]# vim pod-busybox-command-args.yaml
apiVersion: v1
kind: Pod
metadata:
name: pod-busybox-command-args
labels:
name: pod-busybox-command-args
spec:
containers:
- name: busybox
image: busybox
imagePullPolicy: IfNotPresent
command: ["/bin/sh","-c","sleep 3600"]
[root@Master ~]# kubectl create -f pod-busybox-command-args.yaml
pod/pod-busybox-command-args created
[root@Master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
pod-busybox-command-args 1/1 Running 0 4s
删除pod
[root@Master ~]# kubectl delete pod pod-busybox-command-args
pod "pod-busybox-command-args" deleted
修改方式一:
[root@Master ~]# vim pod-busybox-command-args.yaml
command: ["/bin/sh","-c","sleep 3600"]
修改为
command: ["/bin/sh"]
args: ["-c","sleep 3600"]
[root@Master ~]# kubectl create -f pod-busybox-command-args.yaml
pod/pod-busybox-command-args created
[root@Master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
pod-busybox-command-args 1/1 Running 0 4s
删除pod
[root@Master ~]# kubectl delete pod pod-busybox-command-args
pod "pod-busybox-command-args" deleted
修改方式二:
[root@Master ~]# vim pod-busybox-command-args.yaml
command: ["/bin/sh","-c","sleep 3600"]
修改为
args:
- /bin/sh
- -c
- sleep 3600
[root@Master ~]# kubectl create -f pod-busybox-command-args.yaml
pod/pod-busybox-command-args created
[root@Master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
pod-busybox-command-args 1/1 Running 0 4s
删除pod
[root@Master ~]# kubectl delete pod pod-busybox-command-args
pod "pod-busybox-command-args" deleted