大网数据广告活动
服务器运维问答

How do I access nginx server logs from within Docker?

· 52CE 我爱测

I have Nginx routing requests from the browser to either the Express API or my react server, however, in the console I continue to get xhr requests that are just pending and then timeout with 502 bad gateway error which are gener…

问题原文

原帖链接 · Daniel · CC BY-SA 4.0

I have Nginx routing requests from the browser to either the Express API or my react server, however, in the console I continue to get xhr requests that are just pending and then timeout with 502 bad gateway error which are generally caused by Nginx being unable to pass a request to "upstream", in this case my Express API and normally I would be able to check the /var/log/nginx/ files, but I am not sure how to do that when all this is happening within a Docker container.

I have tried this approach of docker logs <container name/id> command, but I get Error: No such container: <container-id>.

I obtained the container id from the last line after running docker-compose up --build and it says Successfully built <container-id>

I copied that id and ran docker logs <container-id> on a second panel in my iTerm.

I then did a docker ps and got this output:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
f37be54a9e60        complexly_api       "npm run dev"            43 minutes ago      Up 28 minutes                              complexly_api_1
9b87bc0aa343        complexly_nginx     "nginx -g 'daemon of…"   About an hour ago   Up 28 minutes       0.0.0.0:3050->80/tcp   complexly_nginx_1
1e30a05f8e28        complexly_worker    "npm run dev"            About an hour ago   Up 28 minutes                              complexly_worker_1
65611b5a6b05        complexly_client    "npm run start"          About an hour ago   Up 28 minutes                              complexly_client_1
9182b26fb402        redis:latest        "docker-entrypoint.s…"   About an hour ago   Up 28 minutes       6379/tcp               complexly_redis_1
8ca3596d8a50        postgres:latest     "docker-entrypoint.s…"   8 days ago          Up 28 minutes       5432/tcp               complexly_postgres_1

I believe I need to grab one of these container ids and do a docker logs with, but I am not sure.

已采纳解答

原帖链接 · Daniel · CC BY-SA 4.0

The issue appears to be that I was running docker logs on the wrong container.

By running docker ps I saw the different containers I had running and copied the container id of the one marked complexly_nginx and was able to get the logs I was looking for.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-03-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。