How can I save the console outtput from a program running in Docker Desktop?

I’m using Blackvue Sync with Docker Desktop under Windows.

When it runs, I can see console output from the python program in the Docker Desktop UI.

I’d like to look at the log after the desktop completes.
I searched the system for files created within 1 hour of a run.
I found about 20 files with .log extension in the directory "C:\Users\Tim\AppData\Local\Docker\log\host" but none of them contain the console output of the python program this is running in the container.

Is there a setting to enable saving of the console output into a file?
Or do I need to add something to the “docker-compose.yml”?

The file save needs to happen automatically, since the Docker Desktop is run from a script and is unattended.

docker logs [container_name] > /save/path/filename.log

@deanayalon,

Thanks - I was unaware of that command, so I searched and it appears to be intended for the command line.
I tried it, but got an error (Docker Desktop is not running now)

So I put in my run script like this:

docker desktop start
sleep 15
docker-compose up -d
sleep 2500
docker logs 'blackvuesync' >> C:\Data\DEV\BlackVue_Sync\docker-logs-internal.txt
docker desktop stop

including the command
docker logs 'blackvuesync' >> C:\Data\DEV\BlackVue_Sync\docker-logs-internal.txt
in the script that starts and stops docker desktop does not work. It creates a file, but it contains zero bytes.

I tried opening the terminal at the bottom of the Docker Desktop, and entered this command:

PS C:\Users\Tim> docker logs 'blackvuesync' > c:\users\tim\docker-log-0119.txt

This creates the file c:\users\tim\docker-log-0119.txt but it contains 13 lines that say usermod: no changes

The console output of the python program running in the container (blackvuesync.py) is output to the terminal screen, but not saved in the file.

Further details:
From the windows CMD script that starts and stops docker desktop, the docker logs command fails:

c:\Data\DEV\BlackVue_Sync>docker logs 'blackvuesync' >> C:\Data\DEV\BlackVue_Sync\docker-logs--internal.txt
Error response from daemon: No such container: 'blackvuesync'

c:\Data\DEV\BlackVue_Sync>docker logs 'blackvue_sync' >> C:\Data\DEV\BlackVue_Sync\docker-logs--internal.txt
Error response from daemon: No such container: 'blackvue_sync'

At the time this command is run, Docker Desktop is running, and there is a blackvuesync container running.

The container name is displayed as blacvuesync and blackvue_sync in different places in Docker Desktop. I tried both, and neither one is recognized as a container in the docker logs command.

With compose deployments, the project name will be the folder name where the compose file is located, unless the project name is explicitly set. Thus, blackvue_snyc is the project name. Container names in compose deployments, use {project name}_{service name}-{replica number} by default, unless configured otherwise.

Instead of anticipating how the container name will be, you can either configure a fixed container name for the service in the compose file. Or just check the output of docker ps to find the container name, and use this name in your command.

Yes, but not 'blackvuesync'. Remove the apostrophes. If it were used as a quotation mark, it wouldn’t be included in the error message (Note that I tried as I wasn’t sure how PS handled these characters).

But even if you use th correct container name, you might get empty files depending on where the output goes in the container. To the error stream or the standard output stream. It seems Powershell handles the redirection the same way as Linux, so this would redirect the standard output (without error)

docker logs blackvuesync > out.txt

This would redirect only error messages (anything that was sent to the error stream actually)

docker logs blackvuesync 2> err.txt

And on Linux, this would redirect all outputs including error messages

docker logs blackvuesync &> all.txt

But it doesn’t work in my PowerShell so I tried this which worked:

(docker logs blackvuesync 2>&1) > all-on-windows.txt

The parenthesis were necessary. This redirects the error stream to the standard output stream first and then everything is redirected to the file.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.