Assignment Day-2 Answer

Docker Update command

Docker update command is used to change the configurations of one or more docker container dynamically.

[root@ip-172-31-7-40 centos]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15c695103fd0 jenkins/jenkins “/sbin/tini — /usr/…” 19 hours ago Exited (137) 7 minutes ago sharp_albattani
e91a38a225ad ubuntu “bash” 20 hours ago Up 16 minutes practical_shirley
[root@ip-172-31-7-40 centos]#
[root@ip-172-31-7-40 centos]# docker inspect 15c695103fd0 | grep -i cpu
“CpuShares”: 100,
“NanoCpus”: 1000000000,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“CpuCount”: 0,
“CpuPercent”: 0,
[root@ip-172-31-7-40 centos]#

The current CpuShares value for this container is 100. Will update the same using docker update command as below to 10.

[root@ip-172-31-7-40 centos]# docker update -c 10 15c695103fd0
15c695103fd0
[root@ip-172-31-7-40 centos]# docker inspect 15c695103fd0 | grep -i cpu
“CpuShares”: 10,
“NanoCpus”: 1000000000,
“CpuPeriod”: 0,
“CpuQuota”: 0,
“CpuRealtimePeriod”: 0,
“CpuRealtimeRuntime”: 0,
“CpusetCpus”: “”,
“CpusetMems”: “”,
“CpuCount”: 0,
“CpuPercent”: 0,
[root@ip-172-31-7-40 centos]#

Below we will update the pids limit that maximum number of pids we can start in this container.

[root@ip-172-31-7-40 centos]# docker inspect e91a38a225ad| grep -i pid
“Pid”: 2176,
“PidMode”: “”,
“PidsLimit”: 1,
[root@ip-172-31-7-40 centos]# docker update –pids-limit 25 e91a38a225ad
e91a38a225ad
[root@ip-172-31-7-40 centos]#
[root@ip-172-31-7-40 centos]# docker inspect e91a38a225ad| grep -i pid
“Pid”: 2176,
“PidMode”: “”,
“PidsLimit”: 25,
[root@ip-172-31-7-40 centos]#

Docker WAIT command

Docker wait command is used to block untill one or more containers stop and return with the exit code.

Open 2 terminals. Execute docker wait command in 1 terminal with the docker id and it will block. Run docker stop command in other terminal and the waiting terminal should unblock with the exit code.

[root@ip-172-31-7-40 centos]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15c695103fd0 jenkins/jenkins “/sbin/tini — /usr/…” 20 hours ago Up 5 seconds 8080/tcp, 50000/tcp sharp_albattani
e91a38a225ad ubuntu “bash” 20 hours ago Up 2 seconds practical_shirley
[root@ip-172-31-7-40 centos]#
[root@ip-172-31-7-40 centos]# docker stop 15c695103fd0
15c695103fd0
[root@ip-172-31-7-40 centos]#

[root@ip-172-31-7-40 centos]#
[root@ip-172-31-7-40 centos]# docker wait 15c695103fd0
143
[root@ip-172-31-7-40 centos]#

[root@ip-172-31-7-40 centos]# docker wait e91a38a225ad
137
[root@ip-172-31-7-40 centos]#
[root@ip-172-31-7-40 centos]# docker kill e91a38a225ad
e91a38a225ad
[root@ip-172-31-7-40 centos]#

If a docker container is already stopped or killed, the wait command will return immediately with the error code without blocking. Also, if the container is just paused, wait command won’t come out of block state. Wait command only works if the container is stopped and not on only pause.