为什么没有使用 "docker run image command" 启动容器的日志?

Why is there no logs using "docker run image command" to start container?

我使用 docker run genezys/gitlab:7.5.2 命令创建并启动容器:

[root@localhost ~]# docker run genezys/gitlab:7.5.2
/opt/gitlab/embedded/bin/runsvdir-start: line 34: ulimit: max user processes: cannot modify limit: Operation not permitted
/opt/gitlab/embedded/bin/runsvdir-start: line 37: /proc/sys/fs/file-max: Read-only file system
[2015-05-05T05:43:02+00:00] INFO: Forking chef instance to converge...
......

我可以看到终端有日志输出。

但是当我使用 docker run genezys/gitlab:7.5.2 /bin/true 命令时:

[root@localhost ~]# docker run genezys/gitlab:7.5.2 /bin/true
[root@localhost ~]#

没有日志输出。

为什么没有使用 docker run image command 启动容器的日志?

那是因为 /bin/true CMD(来自 docker run genezys/gitlab:7.5.2 /bin/true)覆盖了定义的原始 CMD in the Dockerfile:

# Default is to run runit & reconfigure
CMD ["/usr/local/bin/gitlab.sh"]

因为 GitLab 永远不会 运行(/bin/true),它从不输出任何日志。


docker run有一个COMMAND参数:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

docker run "Overriding Dockerfile image defaults"提到:

Four of the Dockerfile commands cannot be overridden at runtime: FROM, MAINTAINER, RUN, and ADD.
Everything else has a corresponding override in docker run.

包括CMD:

Recall the optional COMMAND in the Docker commandline:

$ sudo docker run [OPTIONS] IMAGE[:TAG|@DIGEST] [COMMAND] [ARG...]

This command is optional because the person who created the IMAGE may have already provided a default COMMAND using the Dockerfile CMD instruction.
As the operator (the person running a container from the image), you can override that CMD instruction just by specifying a new COMMAND.

If the image also specifies an ENTRYPOINT then the CMD or COMMAND get appended as arguments to the ENTRYPOINT.