指定entrypiont
- 错误的姿势
docker run -itd -v /tmp/:/tmp/ jdk-ori 'java -jar /tmp/sms.jar'
- 正确的姿势1
docker run -itd -v /tmp/:/tmp/ jdk-ori java -jar '/tmp/sms.jar'
- 正确姿势2:
docker run -it -itd -v /tmp/:/tmp/ --entrypoint /srv/java/jdk/bin/java jdk-ori -jar /tmp/sms.jar
--entrypoint "/srv/java/jdk/bin/java -jar" 这样是不支持的, 这个传参方式不能加参数 ,而dockerfile里则可以
- 正确姿势3: 挂脚本方式
$ cat /tmp/entry.sh
#!/bin/bash
java -jar $1
docker run -it --rm -v /tmp/:/tmp/ --entrypoint "/tmp/entry.sh" jdk-ori /tmp/sms.jar
也可以指定这些:
https://docs.docker.com/engine/reference/run/#entrypoint-default-command-to-execute-at-runtime
CMD (Default Command or Options)
ENTRYPOINT (Default Command to Execute at Runtime)
EXPOSE (Incoming Ports)
ENV (Environment Variables)
HEALTHCHECK
VOLUME (Shared Filesystems)
USER
WORKDIR
如何在k8s里指定docker run -w 的workdir
$ cat centos.yaml
apiVersion: v1
kind: Pod
metadata:
name: my-centos
labels:
app: centos
spec:
containers:
- name: my-centos
image: centos:6.8
imagePullPolicy: IfNotPresent
command: ["top","-b"]
env:
- name: PWD
value: "/tmp"