EntryPoint vs CMD
- EntryPoint
EntryPoint设置了docker run
之后第一个执行的命令, 例如docker run <image> bash
, 相当于把bash这个命令append给了EntryPoint.
exec syntax(command arguments)
1
2
3ENTRYPOINT ["executable", "param1", "param2"]
eg:
ENTRYPOINT [ "sh", "-c", "echo $HOME" ]script
1
2
3COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["postgres"]
- CMD / command
cmd will be executed after the entrypoint
exec syntax(command arguments)
1
CMD ["executable","param1","param2"]
parameters, for
ENTRYPOINT
instructions1
CMD ["param1","param2"]
- Best practices
Docker推荐,用ENTRYPOINT设置image’s main command. and then using CMD as default flag.
eg:1
2
3FROM ubuntu
ENTRYPOINT ["top", "-b"]
CMD ["-c"]