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

需要登入才可留言!

類似的文章


d-laravel,docker

D-Laravel v1.2.1版變更說明(建議更新,必免踩雷)

D-Laravel v1.2.1版修正說明 use GuzzleHttp\Client; 進行post時.出現存取被拒的問題。 如果您是由舊版升級,您可能需調整etc/default-ssl.conf的設定檔 (如果有該檔) 請調整php:9000變更為web:9000,你可以透過執行一次./console secure調整。 docker-compose設定檔部份,PHP-FPM container變更為network_mode: "service:web"...

docker,phpenv

用光了Docker IPv4 address pool問題解法

可能在舊版的docker環境,使用Docker compose啟動容器時,會碰過下方的錯誤:

 Error response from daemon: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network這其實這是default-address-pools用光的症狀,有些環境,docker-compose預設會使用Class B的私有網路。172段的私有IP是有範圍的,從172.16.0.0到172.31.255.255。也就是說,當我們起動一個docker-compose的Project,就會吃掉一個Class B的私有段,非常豪邁,

linux, cli

如何用find指令,找7天內變動過的檔案

如果我們變更過一些檔案,如何透過命令列找出來呢?