book
  • README
  • cheatsheet
    • bash
      • builtin
      • syntactic sugar
      • cmd
      • havefun
    • text-processing
      • awk
      • sed
      • html
      • json
      • regex
      • unicode
    • osx
    • curl
    • tricky
    • widget
    • proxy
    • colors
    • math
    • media
    • ssl
      • keystore
      • verification
      • server
      • client
      • tricky
    • windows
      • powershell
      • choco
      • wsl
      • wt
      • shortcut
      • clsid
      • env
      • shell:folder
  • vim
    • nvim
    • install
    • color
    • plugins
      • usage
      • other plugins
      • deprecated
    • tricky
    • viml
    • windows
    • troubleshooting
  • devops
    • admin tools
    • ssh
    • git
      • config
      • alias
      • submodule
      • eol
      • example
      • gerrit
        • gerrit API
      • github
      • troubleshooting
      • tricky
      • statistics
    • pre-commit
    • release-tools
    • tmux
      • cheatsheet
    • ansible
    • vault
    • artifactory
      • api
      • cli
      • aql
      • nginx cert
    • klocwork
      • kwadmin
      • kwserver
      • api
      • q&a
    • elk
    • mongodb
    • android
    • mobile
  • jenkins
    • config
      • windows
    • appearance
    • troubleshooting
    • jenkinsfile
      • utility
      • parallel
      • build
      • envvar
      • properties
      • trigger
      • node
    • script
      • job
      • build
      • stage
      • agent
      • security & authorization
      • exception
      • monitor
      • tricky
    • api
      • blueocean
    • cli
    • plugins
      • kubernetes
      • docker
      • shared-libs
      • lockable-resource
      • ansicolor
      • badge
      • groovy-postbuild
      • simple-theme
      • customizable-header
      • artifactory
      • jira-steps
      • job-dsl
      • build-timeline
      • crumbIssuer
      • coverage
      • uno-choice
      • tricky
  • virtualization
    • kubernetes
      • init
        • kubespray
        • kubeadm
          • environment
          • crio v1.30.4
          • docker v1.15.3
          • HA
        • addons
        • etcd
      • kubectl
        • pod
        • deploy
        • replicasets
        • namespace
        • secrets
      • node
      • certificates
      • events
      • kubeconfig
      • kubelet
      • troubleshooting
      • cheatsheet
      • auth
      • api
      • tools
        • monitor
        • helm
        • network
        • minikube
    • docker
      • run & exec
      • voume
      • remove
      • show info
      • dockerfile
      • dockerd
      • tricky
      • troubleshooting
      • windows
    • crio
    • podman
  • ai
    • prompt
  • osx
    • apps
      • init
      • brew
    • defaults
    • system
    • network
    • script
    • tricky
  • linux
    • devenv
    • util
      • time & date
      • output formatting
      • params
      • tricky
    • nutshell
    • disk
    • network
    • troubleshooting
    • system
      • apt/yum/snap
      • authorization
      • apps
      • x11
    • ubuntu
      • systemctl
      • x
    • rpi
  • programming
    • groovy
    • python
      • config
      • basic
      • list
      • pip
      • q&a
    • others
    • archive
      • angular
      • maven
      • mysql
        • installation
        • logs
      • ruby
        • rubyInstallationQ&A
  • tools
    • fonts
    • html & css
    • Jira & Confluence
    • node & npm
      • gitbook
      • hexo
      • github.page
      • code themes
    • app
      • microsoft office
      • vscode
      • virtualbox
      • iterm2
      • browser
      • skype
      • teamviewer
      • others
  • quotes
  • english
Powered by GitBook
On this page
  • docker ps
  • docker list
  • docker inspect
  • docker stats
  • docker system
  • ps format

Was this helpful?

  1. virtualization
  2. docker

show info

PreviousremoveNextdockerfile

Last updated 1 year ago

Was this helpful?

[!TIP|label:references:]

docker ps

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.

.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

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.

  • original

    $ docker ps -a --filter 'status=exited' | head -2
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
    5e5f59e3aff3        3129a2ca29d7        "/configmap-reload -…"   2 months ago        Exited (137) 2 months ago                       k8s_rules-configmap-reloader_prometheus-k8s-0_monitoring_aeba5164-dda4-11ec-b785-0cc47aff0b92_1
  • via foramt

    $ docker ps -f 'status=exited' --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.RunningFor}}\t{{.Status}}\t{{.Ports}}\t{{.Names}}' | head -2
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
    5e5f59e3aff3        3129a2ca29d7        "/configmap-reload -…"   2 months ago        Exited (137) 2 months ago                       k8s_rules-configmap-reloader_prometheus-k8s-0_monitoring_aeba5164-dda4-11ec-b785-0cc47aff0b92_1

docker list

  • sort by image size

    $ docker images --format "{{.ID}}\t{{.Size}}\t{{.Repository}}:{{.Tag}}" | sort -k 2 -hr

docker inspect

reference:

show docker image

$ docker inspect 5b4299c238e5 -f '{{ .Config.Image }}'

show entrypoint

$ docker inspect -f "{{.Path}} {{.Args}} ({{.Id}})" $(docker ps -a -q)
  • or list only

    $ docker inspect -f "{{.Path}} {{.Args}} ({{.Id}})" <name>
    • i.e.:

      $ docker inspect -f "{{.Path}} {{.Args}} ({{.Id}})" bf6f6d166b88
      /usr/bin/tini [-- /usr/local/bin/jenkins.sh] (bf6f6d166b88ed9695b89d859ddc1feb7d2deaf07c64352ad479645b707e0157)
$ docker inspect \
         --format='{{ .Name }}{{ printf "\n" }}{{ range .Config.Env }}{{ printf "\n\t" }}{{ printf . }}{{ end }}' \
         <containerID>
$ docker inspect \
         --format='{{ .Name }}{{ printf "\n" }}{{ range .HostConfig.Binds }}{{ printf "\n\t" }}{{ printf . }}{{ end }}' \
         <containerID>
  • i.e.:

    $ docker inspect \
             --format='{{ .Name }}{{ printf ":\n" }}{{ range .HostConfig.Binds }}{{ printf "\n\t" }}{{ printf . }}{{ end }}' \
             <containerID>
    /k8s_jnlp-s31sk-1rvd0_060d5260-8b42-11ed-9c0f-b883034b82d0_0:
    
      /var/lib/kubelet/pods/060d5260-8b42-11ed-9c0f-b883034b82d0/volumes/kubernetes.io~empty-dir/workspace-volume:/home/marslo
      /var/lib/kubelet/pods/060d5260-8b42-11ed-9c0f-b883034b82d0/volumes/kubernetes.io~secret/default-token-m6bqf:/var/run/secrets/kubernetes.io/serviceaccount:ro
      /var/lib/kubelet/pods/060d5260-8b42-11ed-9c0f-b883034b82d0/etc-hosts:/etc/hosts
      /var/lib/kubelet/pods/060d5260-8b42-11ed-9c0f-b883034b82d0/containers/jnlp/1d0c9319:/dev/termination-log
  • or

    $ docker inspect \
            -f '{{ .Name }}{{ printf ":\n" }}{{ range .Mounts }}{{ printf "\n\t" }}{{ .Type }}{{ printf "\t" }}{{ if eq .Type "bind" }}{{ .Source }}{{ end }}{{ .Name }} => {{ .Destination }}{{ end }}{{ printf "\n" }}' \
            8e59c4dd2f65
    /k8s_jnlp-s31sk-1rvd0_060d5260-8b42-11ed-9c0f-b883034b82d0_0:
    
      bind    /var/lib/kubelet/pods/060d5260-8b42-11ed-9c0f-b883034b82d0/volumes/kubernetes.io~secret/default-token-m6bqf => /var/run/secrets/kubernetes.io/serviceaccount
      volume  6c18dbf9b131a9fb245fe896a56b4f4db33f3f32eb1f2b3fcc10c5e50baf7e4f => /home/devops/.jenkins
      bind    /var/lib/kubelet/pods/060d5260-8b42-11ed-9c0f-b883034b82d0/volumes/kubernetes.io~empty-dir/workspace-volume => /home/devops
      bind    /var/lib/kubelet/pods/060d5260-8b42-11ed-9c0f-b883034b82d0/etc-hosts => /etc/hosts
      bind    /var/lib/kubelet/pods/060d5260-8b42-11ed-9c0f-b883034b82d0/containers/jnlp/1d0c9319 => /dev/termination-log
      volume  69c10d1602dc0af1ad305f21ec74f5c568a735c18c64b7b0cb5e04120159e2bd => /home/devops/.ssh
      volume  02668c553b25d1b3f5ba51c85885fab6abf74296a4c0393d35006737d543a174 => /home/devops/agent
  • or

    $ docker container inspect \
             -f '{{ range .Mounts }}{{ .Type }} : {{ .Source }}:{{ .Destination }}{{ println }}{{  end  }}' \
             <containerID>
$ docker inspect --format='{{.LogPath}}' containername
$ docker inspect --format="{{.Id}}" d40df87b2f87
d40df87b2f87261152d2541b870c6b801c031f8df969e4bd3e9b3c607e6c1698
$ docker images -q -a | xargs docker inspect --format='{{.Id}}{{range $rt := .RepoTags}} {{$rt}} {{end}}'

docker stats

reference:

$ docker stats --format "table {{.Name}}\t{{.CPUPerc}}\t{{.MemUsage}}" <CONTAINER_ID>

# or show all
$ docker ps -q | xargs  docker stats --no-stream

docker system

$ docker system df
TYPE            TOTAL     ACTIVE    SIZE      RECLAIMABLE
Images          5         1         9.81GB    8.384GB (85%)
Containers      1         0         0B        0B
Local Volumes   4449      4         172.2GB   156.7GB (90%)
Build Cache     0         0         0B        0B
$ docker system events --since '24h'
$ docker system prune --all
WARNING! This will remove:
        - all stopped containers
        - all networks not used by at least one container
        - all dangling images
        - all build cache
Are you sure you want to continue? [y/N] y

# prune volume only
$ docker system prune --volumes
$ docker ps -a --format 'CONTAINER ID : {{.ID}} | Name: {{.Names}} | Image:  {{.Image}} |  Ports: {{.Ports}}'
  • id and command

    $ docker ps --no-trunc --format "{{.ID}}: {{.Command}}"
  • id, image and commands

    $ docker ps --no-trunc --format "{{.ID}}: {{.Command}}: {{.Image}}"
  • $ docker inspect --format='{{.LogPath}}' containername
  • $ docker ps --format "table {{.Image}}\t{{.Names}}\t{{.Ports}}\t{{.Status}}"

[!TIP]

[!NOTE]

docker inspect
See full command of running/stopped container in Docker
Docker remove TAG images
Return container settings in JSON format
list environment
check mounts
log path
how to redirect docker logs to a single file
get full container ID
check repo tag
Monitor the Resource Usage of Docker Containers
See Memory and CPU Usage for All Your Docker Containers
How to See Memory and CPU Usage for All Your Docker Containers (on CentOS 6)
How to Monitor the Resource Usage of Docker Containers
df
events
prune
ps format
log path
how to redirect docker logs to a single file
with table
Format command and log output
Format the output (--format)
docker ps
docker list
docker inspect
show docker image
show entrypoint
list environment
check mounts
log path
get full container ID
check repo tag
docker stats
docker system
df
events
prune
ps format
docker status