官术网_书友最值得收藏!

Debugging containers

Often in general work with containers, you will likely have to figure out what is going on with a container that is running, but docker ps is not good enough to provide you with all the information you need to figure things out. For these cases, the first command to use is docker logs. This command displays any output that the container has emitted, including both stdout and stderr streams. For the following logs, I started the same NGINX container from before and accessed its hosted page on localhost:

$ docker run -d \
-p 8080:80 \
nginx

06ebb46f64817329d360bb897bda824f932b9bcf380ed871709c2033af069118

$ # Access the page http://localhost:8080 with your browser

$ docker logs 06ebb46f
172.17.0.1 - - [02/Aug/2017:01:39:51 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.01" "-"
2017/08/02 01:39:51 [error] 6#6: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost:8080"
172.17.0.1 - - [02/Aug/2017:01:39:51 +0000] "GET /favicon.ico HTTP/1.1" 404 169 "-" "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.01" "-"
172.17.0.1 - - [02/Aug/2017:01:39:52 +0000] "GET / HTTP/1.1" 200 612 "-" "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.01" "-"

You can see here that NGINX records all access and the associated response codes that are invaluable to debugging a web server. In general, the output can vary from very useful to garbage depending on what is running the service, but it is usually a good place to start your search. You can also add the -f flag if you want to follow the logs as they are being written, which is very helpful when logs are large and you are trying to filter noise from specific things you are looking for.

主站蜘蛛池模板: 永康市| 云霄县| 宁南县| 襄垣县| 班戈县| 左贡县| 常德市| 永新县| 达孜县| 连江县| 星座| 岳阳市| 垣曲县| 乐山市| 涿鹿县| 钟祥市| 石林| 平陆县| 清河县| 扶沟县| 镇康县| 海林市| 屯昌县| 六安市| 澎湖县| 嘉祥县| 淮滨县| 肥城市| 鄂尔多斯市| 甘南县| 嵊泗县| 宁陵县| 准格尔旗| 本溪市| 神池县| 楚雄市| 邓州市| 开原市| 诸暨市| 张家口市| 神木县|