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

需要登入才可留言!

类似文章


docker

Docker防毒攻略

最近刚看玩延禧攻略,就想来介绍个MacOS扫毒攻略。 这篇文章,教大家用如何用Docker搞定MacOS扫毒。 简单介绍,我们如何透过docker使用防毒软体扫毒。 这里假定目前我的目录是在我的家目录中,所以${PWD}就是目前的所在目录,会被挂载到container内的scan数据夹。 所以,使用clamscan -r /scan/,时就能扫描所有的挡案罗,加上-r的参数会使用递归的方式一层一层的进入子目录扫描。

openai,flax,docker

用容器跑OpenAI官方教程的Python(Flax)

如果您登录了openai的网站,可在此处看到官方的教程说明https://beta.openai.com/docs/quickstart/build-your-applicationAPI的KEY的申请,就在这页的下方就有按钮了+ Create new secret key本篇教您用Docker跑官方OpenAI运行环境。

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"...