本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 Amazon ECS 中設定 Docker 協助程式的詳細輸出
如果 Docker 容器或映像發生問題,您可以在 Docker 協助程式上開啟偵錯模式。使用偵錯提供更多常駐程式的詳細輸出,您可以使用它來擷取從容器登錄檔傳送的錯誤訊息,例如 Amazon ECR。
重要
此程序是針對 Amazon ECS 最佳化 Amazon Linux AMI 所寫入。如需其他作業系統,請參閱 Docker 文件中的啟用偵錯
在 Amazon ECS 最佳化 Amazon Linux AMI 上使用 Docker 協助程式偵錯模式
-
連線到您的容器執行個體。
-
使用文字編輯器開啟 Docker 選項檔案,例如 vi。對於 Amazon ECS 最佳化 Amazon Linux AMI,Docker 選項檔案位於
/etc/sysconfig/docker
。 -
尋找 Docker 選項陳述式,並在字串中新增以引號括住的
-D
選項。注意
如果 Docker 選項陳述式以
#
開頭,請移除該字元以取消陳述式註解並啟用選項。對於 Amazon ECS 最佳化 Amazon Linux AMI,Docker 選項陳述式稱為
OPTIONS
。例如:# Additional startup options for the Docker daemon, for example: # OPTIONS="--ip-forward=true --iptables=true" # By default we limit the number of open files per container OPTIONS="
-D
--default-ulimit nofile=1024:4096" -
儲存檔案並結束您的文字編輯器。
-
重新啟動 Docker 常駐程式。
sudo service docker restart
其輸出如下:
Stopping docker: [ OK ] Starting docker: . [ OK ]
-
重新啟動 Amazon ECS 代理。
sudo service ecs restart
您的 Docker 日誌現在應該會顯示更多的詳細輸出。
time="2015-12-30T21:48:21.907640838Z" level=debug msg="Unexpected response from server: \"{\\\"errors\\\":[{\\\"code\\\":\\\"DENIED\\\",\\\"message\\\":\\\"User: arn:aws:sts::1111:assumed-role/ecrReadOnly/i-abcdefg is not authorized to perform: ecr:InitiateLayerUpload on resource: arn:aws:ecr:us-east-1:1111:repository/nginx_test\\\"}]}\\n\" http.Header{\"Connection\":[]string{\"keep-alive\"}, \"Content-Type\":[]string{\"application/json; charset=utf-8\"}, \"Date\":[]string{\"Wed, 30 Dec 2015 21:48:21 GMT\"}, \"Docker-Distribution-Api-Version\":[]string{\"registry/2.0\"}, \"Content-Length\":[]string{\"235\"}}"