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:
Placeholder | Description |
---|---|
.ID | Container ID |
.Image | Image ID |
.Command | Quoted command |
.CreatedAt | Time when the container was created. |
.RunningFor | Elapsed time since the container was started. |
.Ports | Exposed ports. |
.Status | Container status. |
.Size | Container disk size. |
.Names | Container names. |
.Labels | All labels assigned to the container. |
.Label | 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. |
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"