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?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With