by Devin Yang

建立於: 2年前 ( 更新: 2年前 )

我覺的如果要寫一些自動化功能,或許能夠格式化的輸出容器內容還滿有用的。
以下一些Docker容器格式化顯示指令的參考範例

docker ps --format "{{.ID}}\t{{.Names}}"
#例如執行的名稱加命令
docker ps --format "table {{.Names}}: {{.Command}}" --no-trunc
#有table則會包含欄位名稱
docker ps --filter volume=/data --format "table {{.ID}}\t{{.Mounts}}" --no-trunc
#如果Docker swarm模式也可以用
docker service ls --format "table {{.Name}}\t{{.Ports}}"

格式化

格式化選項 (--format) 使用 Go 模板漂亮地打印容器輸出。
下面列出了 Go 模板的有效佔位符:

佔位符說明
.ID容器ID (Container ID)
.ImageImage ID
.Command引用命令 (Quoted command)
.CreatedAt創建容器的時間 (Time when the container was created.)
.RunningFor自容器啟動以來經過的時間。(Elapsed time since the container was started.)
.Ports開放的連接埠 (Exposed ports.)
.State容器狀態。 Container status (for example; “created”, “running”, “exited”).
.Status容器狀態,包含有關持續時間和運行狀況的詳細信息。Container status with details about duration and health-status.
.Size容器磁碟大小。Container disk size.
.Names容器名稱。Container names.
.Labels分配給容器的所有標籤。All labels assigned to the container.
.Label此容器的特定標籤的值。例如 ‘{{.Label "com.docker.swarm.cpu"}}’。
Value of a specific label for this container. For example ‘{{.Label "com.docker.swarm.cpu"}}’
.Mounts此容器中安裝的捲的名稱。Names of the volumes mounted in this container.
.Networks附加到此容器的網絡的名稱。Names of the networks attached to this container.

Tags: docker cli

Devin Yang

文章內容無法一一說明,如果您有什麼不了解處,歡迎提問哦:)

No Comment

Post your comment

需要登入才可留言!

類似的文章


openspeedtest,docker,phpenv

用phpenv跑openspeedtest

雖然我們可能會用speedtest之類網站進行上下傳的速度的測試,那如果我們想測自己的Server的速度呢?像是用戶在別的國家,連到我們的主機速度快慢 ,這時self-hosted的測試工具就很方便啦。最新版本的phpenv在services的yml檔中,加入了openspeedtest.yml囉。

docker

[必學]在docker swarm環境必學iptabels的使用

首先Docker在Linux的環境下,Docker使用iptables規則來提供網路隔離。然而在Docker swarm mode的環境下,我們是沒辨法把連接埠開在host的127.0.0.1下的,這時便可透過iptables中的DOCKER-USER chain來自訂規則囉 。

docker,goaccess,config

phpenv實戰GoAccess即實網站分析(docker版)

在開始前我先說一下,GoAcess也能產出靜態資料只要您有log,因為我覺的即時感覺比較炫,所以本文將專注在GoAccess即時顯示的部分進行介紹。雖然Google Analytics(GA)很好用,但試試另一種GA感覺也很不錯,例如您想了解網站使用者用什麼瀏覽器訪網站。