for-mac icon indicating copy to clipboard operation
for-mac copied to clipboard

Docker logs --follow sometimes doesn't work; requires container to be rebuilt

Open tjratch opened this issue 10 years ago • 30 comments

Expected behavior

When I run docker logs -f my_container it should continuously output the STDOUT from the container

Actual behavior

Sometimes, docker logs -f my_container will only output latest from the STDOUT, but not continue to follow. I have found that rebuilding my container fixes the problem, but doing that often wastes a lot of time.

Information

Diagnostic ID: 502F4185-9F63-42A1-B498-D87A0A0DD908 Docker for Mac: 1.12.0-a (Build 11213) macOS: Version 10.10.4 (Build 14E46) [OK] docker-cli [OK] app [OK] moby-syslog [OK] disk [OK] virtualization [OK] system [OK] menubar [OK] osxfs [OK] db [OK] slirp [OK] moby-console [OK] logs [OK] vmnetd [OK] env [OK] moby [OK] driver.amd64-linux

Steps to reproduce

  1. run docker logs -f my_container

tjratch avatar Aug 16 '16 17:08 tjratch

I'm not sure why rebuilding the container would fix the problem -- that is very odd. Do you mean restarting the container fixes it? Perhaps starting your container takes a lot of time?

Would it be possible for you to share an example container/Dockerfile that exhibits this issue? If not your exact use case, perhaps there is a similar container that is freely shareable and shows the same issue?

dsheets avatar Aug 17 '16 10:08 dsheets

Hi There,

I actually do mean rebuilding my containers (i.e. docker-compose build) fixes the problem. Just restarting them does not seem to work. I can double check the next time it occurs.

Tristan

On Wed, Aug 17, 2016 at 6:45 AM, David Sheets [email protected] wrote:

I'm not sure why rebuilding the container would fix the problem -- that is very odd. Do you mean restarting the container fixes it? Perhaps starting your container takes a lot of time?

Would it be possible for you to share an example container/Dockerfile that exhibits this issue? If not your exact use case, perhaps there is a similar container that is freely shareable and shows the same issue?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/docker/for-mac/issues/307#issuecomment-240377047, or mute the thread https://github.com/notifications/unsubscribe-auth/ANg1NW_U9VTAvaVIYVsg9C5IW5tgOcAQks5qguZRgaJpZM4Jlq2m .

tjratch avatar Aug 17 '16 13:08 tjratch

I am also seeing this issue. Seems to be guaranteed to happen if you sleep your mac.

Restarting an already built container doesn't help, docker start foo , the logs still fail to follow. If you docker rm foo and docker run --name foo <my 500 options> then following works, docker logs -f foo.

hypergig avatar Aug 17 '16 18:08 hypergig

a very janky workaround

watch -t docker logs --tail 50 foo

hypergig avatar Aug 17 '16 18:08 hypergig

I've tried to reproduce this and cannot. Could either of you please post an example Dockerfile or docker-compose.yml that exhibits the issue along with instructions for how to trigger the issue? Even if it only happens 10% of the time, that's fine.

dsheets avatar Aug 18 '16 10:08 dsheets

@dsheets sure thing. Maybe it is actually an issue with the terminal we are using? I am using the native mac Terminal, I can test it with iterm to see if it crops up.

hypergig avatar Aug 18 '16 11:08 hypergig

So I tried a very simple test

docker run -d --name=follow_test busybox sh -c 'while true; do date;sleep 1;done;'

Then attempted to restart docker and sleep mac and I also wasn't able to reproduce.

The first time I noticed this issue was with a container derived from the ethereum/client-go:alpine image. After starting up a fresh container, following the logs works great. Put my mac to sleep and wake it up, the logs do not seem to follow any longer. With this image I am able to repro it.

Going to dig deeper.

hypergig avatar Aug 18 '16 11:08 hypergig

👍 I have the same issue and was just about to submit an issue when I found yours.

Expected behavior

docker logs -f [image] should follow the logs.

Actual behavior

After some indeterminate amount of time and restarting a running image, docker logs -f simply returns to the next line and does not follow the logs.

Information

Diagnostic ID: 5131D56C-EB5B-4FEB-A9ED-9D0D9BA53417 Docker for Mac: 1.12.0-a (Build 11213) macOS: Version 10.11.6 (Build 15G31) [OK] docker-cli [OK] app [OK] moby-syslog [OK] disk [OK] virtualization [OK] system [OK] menubar [OK] osxfs [OK] db [OK] slirp [OK] moby-console [OK] logs [OK] vmnetd [OK] env [OK] moby [OK] driver.amd64-linux

Steps to reproduce

  1. Start a docker image
  2. Run docker logs -f --since=1m [imagename]
  3. On a newly created image, this works. After the image has been running for a few days, it stops after restarting the image: docker restart [imagename] && docker logs -f since=1m [imagename]
  4. Removing the image and re-creating it resolves the issue for a little while, but the issue comes back.

The container continues to run normally, and docker logs --tail 50 show up-to-date logs for the image. I am just unable to follow the logs with docker logs -f [imagename]

chrisbethelepb avatar Aug 18 '16 12:08 chrisbethelepb

Dockerfile:

FROM node:6.3.0

RUN useradd --user-group --create-home --shell /bin/false app 

ENV HOME=/home/app

COPY . $HOME/
RUN chown -R app:app $HOME

USER app
WORKDIR $HOME/

CMD ["node", "app.js"]

docker-compose.yml:

myproject:
  build: .
  environment:
    NODE_ENV: production 
  ports:
    - '8080'

Building the image:

# build the image
docker build -t myproject:latest .

# create the container
# cd in to project directory
docker create --name=myproject --net=localdev -v $(pwd):/home/app myproject:latest

My example just runs a node.js app. You can create an app.js file and put

setInterval(() => {console.log((new Date).getTime())}, 1000);

chrisbethelepb avatar Aug 18 '16 12:08 chrisbethelepb

@chrisbethelepb I am having some difficulty forcing the issue to happen, when you say "After the image has been running for a few days" is that the only way you have been able to repo it thus far?

hypergig avatar Aug 18 '16 12:08 hypergig

@hypergig Yes, it seems to be random intervals of time after it stops working.

chrisbethelepb avatar Aug 18 '16 12:08 chrisbethelepb

@hypergig I typically leave my laptop on and lock the screen after I'm finished working. The machine never goes to full sleep (just turns display off) and my Docker images remain on and produce logs throughout the day. Some of the logs to stdout are very chatty, it's almost like it reaches a certain size and logs -f just stops working.

Edit: The last one that stopped working quit after about a day and a half of uptime. The image and container were freshly built a day and a half ago. As I modify code throughout the day, I will restart the process by running docker restart myproject && docker logs -f --since=1m myproject

chrisbethelepb avatar Aug 18 '16 12:08 chrisbethelepb

@chrisbethelepb funny you should suggest that.. I was just testing this exact theory by

docker run -d --name=follow_test busybox sh -c 'while true; do date; done;'

Which produces about 4211 lines of log per second. I still wasn't able to repro. I restarted docker, the container, slept my mac, nothing triggered it. I wonder what causes the issue...

hypergig avatar Aug 18 '16 13:08 hypergig

@hypergig I never had the problem until the v1.12.0-a build 11213 update. Worked great using the Docker for Mac betas... although I tried installing v1.12.0 (without the -a, original GM release) over top of the current Docker and then it started having the same problem as well.

chrisbethelepb avatar Aug 18 '16 13:08 chrisbethelepb

I'm using iTerm, so I don't think it's the terminal

tjratch avatar Aug 18 '16 13:08 tjratch

This sounds a lot like https://github.com/docker/docker/issues/27779. @thaJeztah does that sound likely to you?

ijc avatar Nov 16 '16 17:11 ijc

I've completely abandoned Docker for Mac and have reverted back to using Kitematic. Docker for mac ended up eating all my CPU and Memory and was somehow slower than Kitematic.

tjratch avatar Nov 16 '16 17:11 tjratch

@ijc25 does look plausible yes

thaJeztah avatar Nov 17 '16 23:11 thaJeztah

@thaJeztah thanks for confirming. This should therefore be fixed in beta when docker for mac switches to the 1.13 rcs and in stable once 1.13 proper is released.

ijc avatar Nov 18 '16 11:11 ijc

1.13.0-rc3-beta33.1 still has the problem

testn avatar Dec 22 '16 00:12 testn