1. 借鑒
2. 開始
在docker中因為配置錯誤呢燥,導(dǎo)致容器一直無法啟動,使用docker logs -f containerId
發(fā)現(xiàn)報錯但是只能隔岸觀火噶咋整诈茧。
【緣起】
nginx因為配置問題導(dǎo)致無法啟動,docker ps
查看不到進程號
我們使用docker logs查看一下日志
docker logs -f nginx01
172.17.0.1 - - [02/Dec/2019:09:47:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
172.17.0.1 - - [02/Dec/2019:09:47:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
172.17.0.1 - - [02/Dec/2019:09:47:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
172.17.0.1 - - [02/Dec/2019:09:47:29 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
2019/12/02 09:49:45 [error] 6#6: *6 open() "/usr/share/nginx/html/aaa" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /aaa HTTP/1.1", host: "localhost:8080"
172.17.0.1 - - [02/Dec/2019:09:49:45 +0000] "GET /aaa HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
2019/12/02 09:50:08 [error] 6#6: *6 open() "/usr/share/nginx/html/50x" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /50x HTTP/1.1", host: "localhost:8080"
172.17.0.1 - - [02/Dec/2019:09:50:08 +0000] "GET /50x HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
172.17.0.1 - - [04/Dec/2019:07:00:31 +0000] "GET /swagger/index.html HTTP/1.1" 404 555 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" "-"
2019/12/04 07:00:31 [error] 6#6: *12 open() "/usr/share/nginx/html/swagger/index.html" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /swagger/index.html HTTP/1.1", host: "localhost:8080"
2020/07/24 15:17:12 [emerg] 1#1: invalid number of arguments in "use" directive in /etc/nginx/nginx.conf:11
nginx: [emerg] invalid number of arguments in "use" directive in /etc/nginx/nginx.conf:11
2020/07/24 15:17:45 [emerg] 1#1: invalid number of arguments in "use" directive in /etc/nginx/nginx.conf:11
nginx: [emerg] invalid number of arguments in "use" directive in /etc/nginx/nginx.conf:11
由此我們可以看到是因為/etc/nginx/nginx.conf這個文件的11行有問題導(dǎo)致的。
【解決】
- 如果配置了路徑映射,直接修改對應(yīng)的文件乘客,重啟即可。
- 如果沒有設(shè)置路徑映射淀歇,將容器中的文件復(fù)制到主機易核,修復(fù)之后覆蓋回去即可。
我的這個問題是屬于第二類浪默,所以依次執(zhí)行以下步驟:
① 將/etc/nginx/nginx.conf配置文件cp到主機
docker cp nginx01:/etc/nginx/nginx.conf /Users/xxx/Desktop/
② 修改配置文件
③ 將配置文件寫回容器
docker cp /Users/xxx/Desktop/nginx.conf nginx01:/etc/nginx/nginx.conf
④ 啟動容器
docker start nginx01
⑤ 查看進程號
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
27b898aa3e89 nginx "nginx -g 'daemon of…" 7 months ago Up 5 seconds 0.0.0.0:8080->80/tcp nginx01