Docker Container-Centric Commands for Beginners: Part 2

Docker Container Inspect

docker container inspect : Display detailed information on one or more containers

docker container inspect mycontain
"State": {
"Status": "exited",
"Running": false,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,

Docker Container Commit and Export

Summary Demo — Docker Container Commands

remove-me#!/bin/bash
function SIGINT_trap() {
echo . . . SIGINT signal caught
echo . . . doing SIGINT cleanup
exit
}
function SIGTERM_trap() {
echo . . . SIGTERM signal caught
echo . . . doing SIGTERM cleanup
exit
}
trap SIGINT_trap SIGINT
trap SIGTERM_trap SIGTERM
for i in `seq 1 50`; do
sleep 1
echo -n " . "
echo $i
done
exit 0
nano Dockerfile
FROM alpine:3.8
ENV myvar original value
COPY traps /root/
RUN chmod +x /root/traps
CMD ["/bin/sh", "/root/traps"]
docker build --tag mytraps:demo --file Dockerfile  .
docker container logs mycontain -f
docker container run -d --name mycontain mytraps:demo
docker container kill --signal 15  mycontain
...
. 15
. 16
. 17
. 18
. 19
. . . SIGTERM signal caught
. . . doing SIGTERM cleanup
docker container prune -f
docker container run -d --name mycontain mytraps:demo
docker container kill --signal SIGINT  mycontain
...
. 16
. 17
. 18
. 19
. 20
. . . SIGINT signal caught
. . . doing SIGINT cleanup
docker container prune -f
docker container run -d --name mycontain mytraps:demo
docker container kill --signal SIGKILL  mycontain
...
. 6
. 7
. 8
. 9
. 10
. 11
. 12

Docker Container Wait

Block until one or more containers stop, then print their exit codes

docker container run -d --name mycontain1 mytraps:demo sh -c 'sleep 10;exit 1'
docker container run -d --name mycontain2 mytraps:demo sh -c 'sleep 15;exit 2'
docker container run -d --name mycontain3 mytraps:demo sh -c 'sleep 25;exit 3'
docker container wait mycontain1 mycontain2 mycontain3
docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
6c7fe618e23b mytraps:demo "sh -c 'sleep 25;exi…" 40 seconds ago Exited (3) 14 seconds ago mycontain3
d4e1bb11e55c mytraps:demo "sh -c 'sleep 15;exi…" 43 seconds ago Exited (2) 27 seconds ago mycontain2
bee5cbf37052 mytraps:demo "sh -c 'sleep 10;exi…" 44 seconds ago Exited (1) 33 seconds ago mycontain1
docker ps -a --filter "name=mycontain1"  --filter "name=mycontain2" --filter "name=mycontain3"
docker ps -a --filter "ancestor=mytraps:demo"
docker ps -a | grep mycontain
docker ps -a | grep mytraps
alias mypsa='docker ps -a | grep '
mypsa traps
mypsa contain

docker container port

List port mappings or a specific mapping for the container

Tutorial Cleanup

docker container prune -f 

docker image rm mytraps:demo

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store