docker-笔记

14 篇文章 0 订阅

1.查看详细输出信息

$ docker ps --help

Usage:  docker ps [OPTIONS]

List containers

Options:
  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output    不截断输出
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes
 

eg.docker ps --no-trunc

2. docker-compose pull   # 更新镜像

    docker-compose up -d   # 更新服务

    docker-compose build    # Dockerfile有更新时使用,重新构建镜像

docker-compose up -d nginx                     构建建启动nignx容器

docker-compose exec nginx bash            登录到nginx容器中

docker-compose down                              删除所有nginx容器,镜像

docker-compose ps                                   显示所有容器

docker-compose restart nginx                   重新启动nginx容器

docker-compose run --no-deps --rm php-fpm php -v  在php-fpm中不启动关联容器,并容器执行php -v 执行完成后删除容器

docker-compose build nginx                     构建镜像 。        

docker-compose build --no-cache nginx   不带缓存的构建。

docker-compose logs  nginx                     查看nginx的日志 

docker-compose logs -f nginx                   查看nginx的实时日志

3.docker ps --format           ###使用Go模板打印出容器信息,可以截取自己需要的输出

Valid placeholders for the Go template are listed below:

PlaceholderDescription
.IDContainer ID
.ImageImage ID
.CommandQuoted command
.CreatedAtTime when the container was created.
.RunningForElapsed time since the container was started.
.PortsExposed ports.
.StatusContainer status.
.SizeContainer disk size.
.NamesContainer names.
.LabelsAll labels assigned to the container.
.LabelValue of a specific label for this container. For example '{{.Label "com.docker.swarm.cpu"}}'
.MountsNames of the volumes mounted in this container.
.NetworksNames of the networks attached to this container.

When using the --format option, the ps command will either output the data exactly as the template declares or, when using the table directive, includes column headers as well.

The following example uses a template without headers and outputs the ID and Command entries separated by a colon for all running containers:

$ docker ps --format "{{.ID}}: {{.Command}}"

a87ecb4f327c: /bin/sh -c #(nop) MA
01946d9d34d8: /bin/sh -c #(nop) MA
c1d3b0166030: /bin/sh -c yum -y up
41d50ecd2f57: /bin/sh -c #(nop) MA

To list all running containers with their labels in a table format you can use:

$ docker ps --format "table {{.ID}}\t{{.Labels}}"

CONTAINER ID        LABELS
a87ecb4f327c        com.docker.swarm.node=ubuntu,com.docker.swarm.storage=ssd
01946d9d34d8
c1d3b0166030        com.docker.swarm.node=debian,com.docker.swarm.cpu=6
41d50ecd2f57        com.docker.swarm.node=fedora,com.docker.swarm.cpu=3,com.docker.swarm.storage=ssd

For example:

root:~# docker ps --format "{{.Names}}\t{{.CreatedAt}}:{{.Command}}" --no-trunc
pensive_almeida 2019-08-21 10:42:55 +0400 +04:"docker-entrypoint.sh bash"
jenkins 2019-08-10 12:10:02 +0400 +04:"/sbin/tini -- /usr/local/bin/jenkins.sh"
heuristic_ellis 2019-08-09 12:11:59 +0400 +04:"/usr/local/bin/docker-entrypoint.sh bash"
backup_log      2019-07-25 06:59:15 +0400 +04:"/bin/sh -c ./initialization.sh"
registry        2019-07-19 12:47:06 +0400 +04:"/bin/registry /etc/docker/registry/config.yml"

参考:https://docs.docker.com/engine/reference/commandline/ps/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值