When we run docker-compose up-d
command to run dockers using docker-compose.yml
file, it starts building images or pulling images from the registry. We can see each and every step of this command on the terminal.
I am trying to run this command from a python script. The command starts successfully but after the command, I do not have any idea of how much the process has been completed. Is there any way I can monitor the status of docker-compose up -d
command so that script can let the user (who is using the script) know how much the process has completed or if the docker-compose
command has failed due to some reasons.?
Thanks
CODE:
from pexpect import pxssh
session = pxssh.pxssh()
if not session.login(ip_address,<USERNAME>, <PASSWORD>):
print("SSH session failed on login")
print(str(session))
else:
print("SSH session login successfull")
session.sendline("sudo docker-compose up -d")
session.prompt()
resp = session.before
print(resp)
You can view docker-compose
logs with following ways
docker-compose up -d
to start all services in detached mode (-d)
(you won't see any logs in detached mode)docker-compose logs -f -t
to attach yourself to the logs of all
running services, whereas -f
means you follow the log output and the
-t
option gives you nice timestamps (Docs)