8000 Docker logs cannot redirect or pipe on ConEmu · Issue #41139 · moby/moby · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Docker logs cannot redirect or pipe on ConEmu #41139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cdalexndr opened this issue Jun 22, 2020 · 7 comments
Closed

Docker logs cannot redirect or pipe on ConEmu #41139

cdalexndr opened this issue Jun 22, 2020 · 7 comments

Comments

@cdalexndr
Copy link
cdalexndr commented Jun 22, 2020
8000

Description
Cannot redirect output stream from docker logs using conemu.

Steps to reproduce the issue:
docker logs docker_filebeat_1 > log.txt
or
docker logs docker_filebeat_1 | clip

Describe the results you received:
Both commands show logs in console instead of outputing to file or clipboard.

Describe the results you expected:
Redirect to file and to clipboard.

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker version:

Client: Docker Engine - Community
 Version:           19.03.8
 API version:       1.40
 Go version:        go1.12.17
 Git commit:        afacb8b
 Built:             Wed Mar 11 01:23:10 2020
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.8
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.17
  Git commit:       afacb8b
  Built:            Wed Mar 11 01:29:16 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          v1.2.13
  GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
 runc:
  Version:          1.0.0-rc10
  GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

Output of docker info:

Client:                                                                                            
 Debug Mode: false                                                                                 
                                                                                                   
Server:                                                                                            
 Containers: 10                                                                                    
  Running: 9                                                                                       
  Paused: 0                                                                                        
  Stopped: 1                                                                                       
 Images: 18                                                                                        
 Server Version: 19.03.8                                                                           
 Storage Driver: overlay2                                                                          
  Backing Filesystem: <unknown>                                                                    
  Supports d_type: true                                                                            
  Native Overlay Diff: true                                                                        
 Logging Driver: json-file                                                                         
 Cgroup Driver: cgroupfs                                                                           
 Plugins:                                                                                          
  Volume: local                                                                                    
  Network: bridge host ipvlan macvlan null overlay                                                 
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog              
 Swarm: inactive                                                                                   
 Runtimes: runc                                                                                    
 Default Runtime: runc                                                                             
 Init Binary: docker-init                                                                          
 containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429                                      
 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd                                            
 init version: fec3683                                                                             
 Security Options:                                                                                 
  seccomp                                                                                          
   Profile: default                                                                                
 Kernel Version: 4.19.76-linuxkit                                                                  
 Operating System: Docker Desktop                                                                  
 OSType: linux                                                                                     
 Architecture: x86_64                                                                              
 CPUs: 4                                                                                           
 Total Memory: 3.846GiB                                                                            
 Name: docker-desktop                                                                              
 ID: GPZZ:G6YA:BOI2:3RVR:SHX7:VPW4:HWGG:XBBW:EZBL:I6Y4:MMFZ:IIQI                                   
 Docker Root Dir: /var/lib/docker                                                                  
 Debug Mode: true                                                                                  
  File Descriptors: 120                                                                            
  Goroutines: 122                                                                                  
  System Time: 2020-06-22T09:51:51.513818496Z                                                      
  EventsListeners: 5                                                                               
 Registry: https://index.docker.io/v1/                                                             
 Labels:                                                                                           
 Experimental: false                                                                               
 Insecure Registries:                                                                              
  127.0.0.0/8                                                                                      
 Live Restore Enabled: false                                                                       
 Product License: Community Engine                                                                 

Additional environment details (AWS, VirtualBox, physical, etc.):
Windows 10 1903
Cmder 1.3.13.967 (ConEmu 191012)

Related: #28814

@cdalexndr cdalexndr changed the title Docker logs cannot redirect and pipe on ConEmu Docker logs cannot redirect or pipe on ConEmu Jun 22, 2020
@thaJeztah
Copy link
Member

Your container likely printed (some of) those logs on stderr instead of stdout, so you'll have to redirect both stdout and stderr; https://askubuntu.com/a/625230

Something like

docker logs docker_filebeat_1 &> log.txt

I don't think there's a bug to fix here, so I'm closing this ticket, but feel free to continue the conversation

@cdalexndr
Copy link
Author
cdalexndr commented Jun 22, 2020

Indeed, it seems that filebeat is logging to stderr instead of stdout. Will open an issue with filebeat.

@thaJeztah
Copy link
Member

Logging to stderr is standard practice (https://www.jstorimer.com/blogs/workingwithcode/7766119-when-to-use-stderr-instead-of-stdout), so not sure if they would have to change that

@cdalexndr
Copy link
Author
cdalexndr commented Jun 22, 2020

Note that the docker logs documentation doesn't specify that the logs output can be on stdout AND stderr.
This behavior should be added to the documentation, also with some examples like:

How to find something in logs (both stderr and stdout streams):
docker logs docker_container_1 2>&1 | grep something

Also, I understand that the stream output separation can be used to filter only logs on stderr to find errors if the container's logging is configured this way, but from a console command perspective, shouldn't the stderr be only used when an error occurred executing that command (docker logs)? So the stdout will print the logs and stderr will be used only if docker logs failed to retrieve the logs or some other kind of errors relating to docker logs.

@thaJeztah
Copy link
Member

stderr will be used only if docker logs failed to retrieve the logs or some other kind of errors.

docker logs will preserve where the container's process printed output to (unless the container is started with a TTY attached, in which case the raw stream is returned).

The naming of stderr and stout on Linux is a bit ambiguous. Generally, stdout is used for "main output", and stderr for "other output". This allows process output to be piped to another process, and informational messages still to be printed on the terminal.

@cdalexndr
Copy link
Author

This allows process output to be piped to another process, and informational messages still to be printed on the terminal.

So if docker logs command purpose is to produce log output, shouldn't be printed to stdout (main output) so that the process output to be piped to another process, such as grep to filter logs?

@thaJeztah
Copy link
Member

The docker logs command tries to be transparent so that the containers process output can be processed that way.

If the containers process output streams would be combined to stdout, that would no longer be possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0