Beginners Guide to dockers part 1, has covered the architecture of dockers. Along with this, so far, I have covered different types of dockers installation and how to download, install and delete docker image.
In this post, I will be covering more about docker commands which are really very useful while working with docker containers.
Obtaining Docker Version Information: This command will help to provide information about the docker server and client for your current working configuration. The output of the command states that CE version is being used with API and GO version details. Client deployed on windows platform, it is showing OS is windows. But for server it is showing that OS is linux. This installation has client and server installed on same machine. I am using docker tools to acces the docker server installed on same machine.
PS C:labtest-html> docker version
Client:
Version: 18.03.1-ce
API version: 1.37
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:12:48 2018
OS/Arch: windows/amd64
Experimental: false
Orchestrator: swarm
Server:
Engine:
Version: 18.03.1-ce
API version: 1.37 (minimum version 1.12)
Go version: go1.9.5
Git commit: 9ee9f40
Built: Thu Apr 26 07:22:38 2018
OS/Arch: linux/amd64
Experimental: false
PS C:labtest-html>
Obtaining Docker System Infomration: The next important command is the docker system info command. This command provides information about what mode the Docker engine is operating in (swarm mode or not), what storage driver is used for the union filesystem, what version of the Linux kernel we have on our host, and much more. Please have a careful look at the output generated by your system when running the command. Analyze what kind of information is shown below.
PS C:labtest-html> docker system info
Containers: 15
Running: 1
Paused: 0
Stopped: 14
Images: 14
Server Version: 18.03.1-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
NodeID: ii9vy20o5gwxxmkcve6livhyw
Is Manager: true
ClusterID: x4wi39gjagt28xhvplmv26t64
Managers: 1
Nodes: 1
Orchestration:
Task History Retention Limit: 5
Raft:
Snapshot Interval: 10000
Number of Old Snapshots to Retain: 0
Heartbeat Tick: 1
Election Tick: 10
Dispatcher:
Heartbeat Period: 5 seconds
CA Configuration:
Expiry Duration: 3 months
Force Rotate: 0
Autolock Managers: false
Root Rotation In Progress: false
Node Address: 192.168.65.3
Manager Addresses:
192.168.65.3:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.87-linuxkit-aufs
Operating System: Docker for Windows
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 1.934GiB
Name: linuxkit-00155d010105
ID: DGPH:X3AJ:ZH2F:36YZ:72TG:42Q7:BZIF:P7K4:CXTB:R67Y:NIGZ:7HAG
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: 47
Goroutines: 180
System Time: 2018-05-07T13:00:01.7021005Z
EventsListeners: 2
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
PS C:labtest-html>
Listing The Resource Consumption: The below output is showing how much resources are currently used. Below mentioned output tells that on system I am currently having 14 images locally cached of which 4 are in active use. An image is considered to be in active use if currently at least one running or stopped container is based on it. These images occupy 1.39 GB disk space. I have 15 running containers on my system and 1 stopped ones for a total of 14 containers. I can reclaim the space occupied by the stopped containers which is 472B. I also have 8 active volumes on my host that together consume about 136.5 MB of disk space. Since none of the volumes are in use, I can reclaim 100% of the space.Finally, my Build Cache is currently empty and thus of course I cannot reclaim any space there too.
PS C:labtest-html> docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 14 4 1.594GB 1.395GB (87%)
Containers 15 1 474B 472B (99%)
Local Volumes 8 0 136.5MB 136.5MB (100%)
Build Cache 0B 0B
PS C:labtest-html>
More detailed output can be see by typing the below mentioned command in the terminal window.
PS C:labtest-html> docker system df -v
Images space usage:
REPOSITORY TAG IMAGE ID CREATED ago SIZE SHARED SIZE UNIQUE SiZE CONTAINERS
my-website 1.0 1bbf94f77299 33 hours ago ago 18MB 18MB 71B 1
alpine-ping latest ee997c1cb716 2 days ago ago 5.647MB 4.148MB 1.499MB 0
ubuntu latest 452a96d81c30 9 days ago ago 79.62MB 0B 79.62MB 0
grafana/grafana latest ed6c9eb28b01 10 days ago ago 238.1MB 0B 238.1MB 0
hello-world latest e38bc07ac18e 3 weeks ago ago 1.848kB 0B 1.848kB 0
nginx alpine ebe2c7c61055 3 weeks ago ago 18MB 18MB 0B 0
centos latest e934aafc2206 4 weeks ago ago 198.6MB 0B 198.6MB 3
busybox latest 8ac48589692a 4 weeks ago ago 1.146MB 0B 1.146MB 2
alpine latest 3fd9065eaf02 3 months ago ago 4.148MB 4.148MB 0B 9
google/cadvisor latest 75f88e3ec333 5 months ago ago 62.21MB 0B 62.21MB 0
docker4w/nsenter-dockerd latest cae870735e91 6 months ago ago 187.5kB 0B 187.5kB 0
tutum/influxdb latest c061e5808198 18 months ago ago 289.7MB 224.4MB 65.32MB 0
tutum/influxdb 0.8.8 1f72f5000d33 2 years ago ago 279.9MB 224.4MB 55.53MB 0
fr3nd/collectd latest 8713c4a4964f 2 years ago ago 649.7MB 0B 649.7MB 0
Containers space usage:
CONTAINER ID IMAGE COMMAND LOCAL VOLUMES SIZE CREATED ago STATUS NAMES
247ac71ee498 alpine “/bin/sh” 0 335B 32 hours ago ago Exited (0) 31 hours ago reader
6cb7116dd7b1 alpine “/bin/sh” 0 137B 32 hours ago ago Exited (0) 32 hours ago writer
40c8e9220f5b alpine “-it –name writer e…” 0 0B 32 hours ago ago Created dazzling_chebyshev
0be877206ab2 alpine “-it –name writer a…” 0 0B 32 hours ago ago Created reverent_hopper
641f1371b872 alpine “-it –name writer a…” 0 0B 32 hours ago ago Created trusting_kalam
48ada1420e8e alpine “-it –name writer -…” 0 0B 32 hours ago ago Created clever_kapitsa
95ffa6d5fef4 alpine “-it –name write-pe…” 0 0B 32 hours ago ago Created elastic_lamport
fa5c8db3b550 alpine “-it –name write-pe…” 0 0B 32 hours ago ago Created kind_wing
3f432b2883f8 my-website:1.0 “nginx -g ‘daemon of…” 0 2B 33 hours ago ago Up 33 hours my-site
634013c5b179 alpine “ssh 127.0.0.1” 0 0B 2 days ago ago Created pedantic_edison
c99bb072398a busybox “-it exec /bin/sh” 0 0B 2 days ago ago Created zen_kare
b0825921b5c5 busybox “exec /bin/bash” 0 0B 2 days ago ago Created priceless_bardeen
23e23f63ce00 centos “exec ping -c 127.0.…” 0 0B 3 days ago ago Created dazzling_turing
dfebc236e05f centos “/etc/*release*” 0 0B 3 days ago ago Created priceless_allen
9efc9e9ef4ae centos “ifconfig -a” 0 0B 3 days ago ago Created hungry_hugle
Local Volumes space usage:
VOLUME NAME LINKS SIZE
f9af4287f9891dd7c3b42d77b1657f6c1405fe622dcbe6e3f909ae40aad470ba 0 33.63MB
my-data 0 0B
00b2ec861da114fad3d09e1c174c918a34dcd88d14c7b4069e2c159c1ab06885 0 33.58MB
103fe18d6d3f8c0b2cae8d798edd1aeaa3b1fd448f838634749d9bf9f83e50fd 0 2.028MB
22de30eca1e1859257568153d4c2b79567832b56076ea7adea3db725bbd5fea4 0 869B
3dbfc337ac718416e53c2ead7dfb234b151862984741c2d1dae518cfe1169609 0 33.64MB
6276c3f403c651df7d5fa86f4d23c3033a134412393beb3e545892c1f716cef4 0 0B
6b864603f18146911e5c165a995b480321df71f4c03c1a7a252bc458c157deca 0 33.6MB
Build cache usage: 0B
PS C:labtest-html>
Checking the Status of the Docker Events: I liked the below mentioned command because it actually tells me what is happening in the background whenever I run any of the docker command.
PS C:Labtest-html> docker system events
I would suggest to open a new window and run the docker standard start or stop command. I am going to run a hello-world docker container and correspondingly we can see the list of events which are happening in background in the preious open terminal where we have issued the “Docker System Events” command.
PS C:labtest-html> docker run hello-world
Events generated on another terminal:
PS C:Labtest-html> docker system events
2018-05-07T18:43:52.277871400+05:30 container create e2e7a06a242fabcf36fea77d4f245c5f6d629f2b60c6170b47a45f0c056932f7 (image=hello-world, name=wonderful_euler)
2018-05-07T18:43:52.287628100+05:30 container attach e2e7a06a242fabcf36fea77d4f245c5f6d629f2b60c6170b47a45f0c056932f7 (image=hello-world, name=wonderful_euler)
2018-05-07T18:43:52.508228600+05:30 network connect 0e7a9971d8030271ef932b0556ca31e88bfede6ed213b1b1c1923847bb96c506 (container=e2e7a06a242fabcf36fea77d4f245c5f6d629
f2b60c6170b47a45f0c056932f7, name=bridge, type=bridge)
2018-05-07T18:43:52.996369000+05:30 container start e2e7a06a242fabcf36fea77d4f245c5f6d629f2b60c6170b47a45f0c056932f7 (image=hello-world, name=wonderful_euler)
2018-05-07T18:43:53.081629600+05:30 container die e2e7a06a242fabcf36fea77d4f245c5f6d629f2b60c6170b47a45f0c056932f7 (exitCode=0, image=hello-world, name=wonderful_eul
er)
2018-05-07T18:43:53.432605800+05:30 network disconnect 0e7a9971d8030271ef932b0556ca31e88bfede6ed213b1b1c1923847bb96c506 (container=e2e7a06a242fabcf36fea77d4f245c5f6d
629f2b60c6170b47a45f0c056932f7, name=bridge, type=bridge)
The above mentioned list of commands and respective outputs are really helpful while troubleshooting. Here is the beginning of my post.