Task 1
What is the version of the Docker Server Engine running on the host?
$ docker version
Client:
Version: 25.0.5
API version: 1.44
Server:
Engine:
Version: 25.0.5
API version: 1.44Answer: 25.0.5
Task 2
How many containers are currently running on this host?
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESAnswer: 0
Task 3
How many images are available on this host?
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest f6b0ca07d79d 7 months ago 934MB
postgres latest a38f9f77ff88 7 months ago 456MB
alpine latest 706db57fb206 7 months ago 8.32MB
nginx alpine 5e7abcdd2021 7 months ago 52.7MB
nginx latest 657fdcd1c365 7 months ago 152MB
redis latest 466e5b1da2ef 8 months ago 137MB
ubuntu latest 97bed23a3497 8 months ago 78.1MB
kodekloud/simple-webapp-mysql latest 129dd9f67367 7 years ago 96.6MB
kodekloud/simple-webapp latest c6e3cd9aae36 7 years ago 84.8MBAnswer: 9
Task 4
Run a container using the redis image.
$ docker run -d redis
ea9f70db6bf97954f00b670654645f0136a7869829588d4b4b420c31f277eb6eTask 5
Stop the container you just created.
$ docker container stop ea9f70db6bf9
ea9f70db6bf9Task 6
How many containers are running on this host now?
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESAnswer: 0
Task 7
How many containers are running on this host now? (A few containers were created automatically.)
$ docker ps -q | wc -l
4Answer: 4
Task 8
How many containers are present on the host, including both running and stopped containers?
$ docker ps -aq | wc -l
6Answer: 6
Task 9
What image is used by the nginx-1 container?
$ docker ps --filter "name=nginx-1"
0c1a0918e01a nginx:alpine "/docker-entrypoint.…" 5 minutes ago Up 5 minutes 80/tcp nginx-1Answer: nginx:alpine
Task 10
What is the name of the container created from the ubuntu image?
$ docker ps --filter "ancestor=ubuntu"
9f0f8bb95240 ubuntu "sleep 1000" 6 minutes ago Up 6 minutes awesome_northcutAnswer: awesome_northcut
Task 11
What is the ID of the stopped container that uses the alpine image?
$ docker ps -a
--filter="status=exited"
--filter="ancestor=alpine"
--format "{{.ID}}"
4db9a05cfe21Answer: 4db9a05cfe21
Task 12
What is the state of the stopped Alpine container?
$ docker ps -a
--filter="ancestor=alpine"
--format "{{.Status}}"
Exited (0) 19 minutes ago
Exited (0) 2 minutes agoAnswer: Exited
Task 13
Delete all containers from the Docker host, including both running and stopped containers.
$ docker rm -f $(docker ps -a -q)For scripting & automation, you can use:
docker rm -f $(docker ps -a -q) 2>/dev/null || trueVerify:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESTask 14
Delete the ubuntu image.
docker image rm ubuntuVerify:
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql latest f6b0ca07d79d 7 months ago 934MB
postgres latest a38f9f77ff88 7 months ago 456MB
alpine latest 706db57fb206 7 months ago 8.32MB
nginx latest 657fdcd1c365 7 months ago 152MB
nginx alpine 5e7abcdd2021 7 months ago 52.7MB
redis latest 466e5b1da2ef 8 months ago 137MB
kodekloud/simple-webapp-mysql latest 129dd9f67367 7 years ago 96.6MB
kodekloud/simple-webapp latest c6e3cd9aae36 7 years ago 84.8MBTask 15
Pull the nginx:1.14-alpine image.
Only pull the image. Do not create a container.
$ docker pull nginx:1.14-alpine
1.14-alpine: Pulling from library/nginx
Digest: sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7
Status: Downloaded newer image for nginx:1.14-alpineTask 16
Run a container using the image name nginx:1.14-alpine and name it webapp.
$ docker run -d --name webapp nginx:1.14-alpine
843c122d8ca6d21bca3c8dd915e92df4620f5127e1e4ecff1dcb92917d3ee611Verify:
$ docker ps
CONTAINER ID IMAGE COMMAND STATUS NAMES
843c122d8ca6 nginx:1.14-alpine "nginx -g 'daemon..." Up webappTask 17
Cleanup: Delete all images on the host.
Remove containers if necessary.
Step 1: Stop all running containers
docker rm -f $(docker ps -q)Step 2: Remove all images
docker rmi -f $(docker images -aq)Step 3: Verify cleanup
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE