[!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

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)
    

list environment

$ docker inspect \
         --format='{{ .Name }}{{ printf "\n" }}{{ range .Config.Env }}{{ printf "\n\t" }}{{ printf . }}{{ end }}' \
         <containerID>

check mounts

$ 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>
    

log path

[!TIP] how to redirect docker logs to a single file

$ docker inspect --format='{{.LogPath}}' containername

get full container ID

$ docker inspect --format="{{.Id}}" d40df87b2f87
d40df87b2f87261152d2541b870c6b801c031f8df969e4bd3e9b3c607e6c1698

check repo tag

$ docker images -q -a | xargs docker inspect --format='{{.Id}}{{range $rt := .RepoTags}} {{$rt}} {{end}}'

docker stats

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

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

docker system

df

$ 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

events

$ docker system events --since '24h'

prune

$ 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

ps format

$ 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
  • with table

    $ docker ps --format "table {{.Image}}\t{{.Names}}\t{{.Ports}}\t{{.Status}}"
    
Copyright © marslo 2020-2024 all right reserved,powered by GitbookLast Modified: 2024-10-30 04:30:30

results matching ""

    No results matching ""