Unable to use -lt when running Nginx Docker or cat logs
Asked Answered
H

2

13

I've recently pulled a nginx image:

docker pull nginx

I can run it successfully and go to http://server_name and see the "Welcome to Nginx" page:

docker run -d -p 80:80 nginx

But then when I try to check logs:

docker exec 6c79549e3eb4f6e5fc06f049b67814ac4560ce2cdd7cc6ae84b44b5ae09a9a05 cat /var/log/nginx/access.log

It just hangs and outputs nothing. Same with error log. Now if I create a test.txt file in that same folder and use docker exec to (view) cat the file, I executes without hanging or any issues.

Even if I try to run it in interactive mode, it just hangs:

docker run -i -t -p 80:80 nginx

Once again the terminal hangs on the next line doing nothing, but it seems to work because I can access the nginx welcome page.

Really confused what is going on, I've tried to search for this problem, but have not found any solution so far. Without being able to view the logs, it is going to be pretty hard to debug :) Also shouldn't the access logs be moved to stdout in the nginx container since by convention docker containers log to stdout?

Hubbell answered 15/5, 2015 at 22:29 Comment(3)
Does the file /var/log/nginx/access.log exist in the container? Try to get into the container and run commands interactively with docker run -i -t -p 80:80 nginx /bin/bashMarolda
Yes, the access.log is there root@ip-10-232-1-195:~/docker-registry/dockerfiles# docker exec d24a412224684434dfe9cf950015619ca4fc397e235602649591e2e5c46f4194 ls /var/log/nginx/access.log /var/log/nginx/access.logHubbell
Run ls -al instead of just ls and post the output.Marolda
S
32

If you go inside the container docker exec -it <container-id> /bin/bash and check the log location ls -la /var/log/nginx/, you will see the following output: lrwxrwxrwx 1 root root 11 Apr 30 23:05 access.log -> /dev/stdout lrwxrwxrwx 1 root root 11 Apr 30 23:05 error.log -> /dev/stderr Clearly, the logs are written in stdout. You can also try doing cat access.log inside the container and it still doesn't show anything.
Now, the right way to get your logs is going outside the container and doing docker logs <container-id> Then, you would see your logs. Hope this helps!

Siclari answered 15/5, 2015 at 23:6 Comment(3)
Thank you :) I see the output now, I think that was an error on my part, i kept using the wrong IP address.Hubbell
this worked for me but I had to use /bin/sh instead as my container did not have bash installedHaydenhaydn
this is correct, but docker logs only shows very limited log, it means till today every log in nginx is lost ?Tanney
B
0

You can also mount your folder into /var/log/nginx. Then nginx will create log files as regular files and you can see them in the host

docker run -d nginx -p 8000:80 -v /myhostlogs:/var/log/nginx
curl http://localhost
cat /myhostlogs/access.log
Bobo answered 25/3, 2024 at 21:43 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.