Custom docker run output in detached mode

706 views Asked by At

I just wondering if it was possible to print Dockerfile's CMD output when I run docker run ....

I setup jenkins on an image and it would be convenient to have the defautl admin password displayed directly when running the image. Here is what I have in mind :

# 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"]

I have tried to follow this post but I may not understand the solution:

Redirecting command output in docker

My desired output would look like this:

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

And above all I wonder if this follows docker's good practices.

UPDATE

# 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

There are 0 answers