自定义docker在分离模式下运行输出

时间:2020-09-30 15:10:02

标签: docker dockerfile docker-run

我只是想知道运行 docker run ... 时是否可以打印Dockerfile的CMD输出。

我在图像上设置了詹金斯,在运行图像时直接显示defautl管理员密码会很方便。这就是我的想法:

# Dockerfile

...
RUN systemctl enable jenkins
CMD ["/usr/bin/systemctl", "start", "jenkins"]
CMD ["/usr/bin/echo", "Jenkins default password : "]
CMD ["/usr/bin/cat", "/var/lib/jenkins/secrets/initialAdminPassword"]

我试图关注这篇文章,但我可能不了解解决方案:

Redirecting command output in docker

我想要的输出看起来像这样:

$ docker run -tid auto-server:1.0
c93f26eb1756ce98332a9be8dd88a824e65ab9c1342df762c8a62b9d62c13dcc
Jenkins default password : 
<the-jenkins-password>
$

最重要的是,我想知道这是否遵循docker的良好做法。

更新

# output when I only keep CMD ["/usr/bin/systemctl", "start", "jenkins"]

$ docker logs auto-server
jenkins: Correct java version found
jenkins:  * Starting Jenkins Automation Server jenkins
jenkins:    ...done.

$ docker exec -ti auto-server bash
root@42dbec3a6eaa:/home/ubuntu# systemctl status jenkins
jenkins.service - Controls Jenkins Automation Server
    Loaded: loaded (/etc/init.d/jenkins, disabled)
    Active: active (running)
root@42dbec3a6eaa:/home/ubuntu# 

0 个答案:

没有答案