Docker feature

Posted on 2018-08-07

EntryPoint vs CMD

  1. EntryPoint
    EntryPoint设置了docker run之后第一个执行的命令, 例如docker run <image> bash, 相当于把bash这个命令append给了EntryPoint.
  • exec syntax(command arguments)

    1
    2
    3
    ENTRYPOINT ["executable", "param1", "param2"]
    eg:
    ENTRYPOINT [ "sh", "-c", "echo $HOME" ]
  • script

    1
    2
    3
    COPY ./docker-entrypoint.sh /
    ENTRYPOINT ["/docker-entrypoint.sh"]
    CMD ["postgres"]
  1. CMD / command
    cmd will be executed after the entrypoint
  • exec syntax(command arguments)

    1
    CMD ["executable","param1","param2"]
  • parameters, for ENTRYPOINT instructions

    1
    CMD ["param1","param2"]
  1. Best practices
    Docker推荐,用ENTRYPOINT设置image’s main command. and then using CMD as default flag.

eg:

1
2
3
FROM ubuntu
ENTRYPOINT ["top", "-b"]
CMD ["-c"]