Profile picture
Sidharth R
  • Home
  • Posts
  • Journal
  • Labs
  • Home
  • Posts
  • Journal
  • Search
  1. Home
  2. Labs
  3. Docker labs
  4. Docker Basic Commands

Docker Basic Commands

MEDIUM Jun 2026 ~60 min kodekloud ↗ loading... views

Task 1

What is the version of the Docker Server Engine running on the host?

Check Docker version
$ docker version

Client:
Version:           25.0.5
API version:       1.44

Server:
Engine:
Version:          25.0.5
API version:      1.44

Answer: 25.0.5

Task 2

How many containers are currently running on this host?

List running containers
$ docker ps

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS   PORTS   NAMES

Answer: 0

Task 3

How many images are available on this host?

List Docker images
$ 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.8MB

Answer: 9

Task 4

Run a container using the redis image.

Run Redis container
$ docker run -d redis

ea9f70db6bf97954f00b670654645f0136a7869829588d4b4b420c31f277eb6e

Task 5

Stop the container you just created.

Stop Redis container
$ docker container stop ea9f70db6bf9

ea9f70db6bf9

Task 6

How many containers are running on this host now?

Verify running containers
$ docker ps

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS   PORTS   NAMES

Answer: 0

Task 7

How many containers are running on this host now? (A few containers were created automatically.)

Count running containers
$ docker ps -q | wc -l

4

Answer: 4

Task 8

How many containers are present on the host, including both running and stopped containers?

Count all containers
$ docker ps -aq | wc -l

6

Answer: 6

Task 9

What image is used by the nginx-1 container?

Inspect nginx-1 container
$ docker ps --filter "name=nginx-1"

0c1a0918e01a   nginx:alpine   "/docker-entrypoint.…"   5 minutes ago   Up 5 minutes   80/tcp   nginx-1

Answer: nginx:alpine

Task 10

What is the name of the container created from the ubuntu image?

Find Ubuntu container
$ docker ps --filter "ancestor=ubuntu"

9f0f8bb95240   ubuntu   "sleep 1000"   6 minutes ago   Up 6 minutes   awesome_northcut

Answer: awesome_northcut

Task 11

What is the ID of the stopped container that uses the alpine image?

Find stopped Alpine container
$ docker ps -a 
--filter="status=exited" 
--filter="ancestor=alpine" 
--format "{{.ID}}"

4db9a05cfe21

Answer: 4db9a05cfe21

Task 12

What is the state of the stopped Alpine container?

Check Alpine container status
$ docker ps -a 
--filter="ancestor=alpine" 
--format "{{.Status}}"

Exited (0) 19 minutes ago
Exited (0) 2 minutes ago

Answer: Exited

Task 13

Delete all containers from the Docker host, including both running and stopped containers.

Delete all containers
$ docker rm -f $(docker ps -a -q)

For scripting & automation, you can use:

DOCKER
docker rm -f $(docker ps -a -q) 2>/dev/null || true

Verify:

Verify container cleanup
$ docker ps -a

CONTAINER ID   IMAGE   COMMAND   CREATED   STATUS   PORTS   NAMES

Task 14

Delete the ubuntu image.

DOCKER
docker image rm ubuntu

Verify:

Verify image removal
$ 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.8MB

Task 15

Pull the nginx:1.14-alpine image.

Only pull the image. Do not create a container.

Pull NGINX image
$ docker pull nginx:1.14-alpine

1.14-alpine: Pulling from library/nginx
Digest: sha256:485b610fefec7ff6c463ced9623314a04ed67e3945b9c08d7e53a47f6d108dc7
Status: Downloaded newer image for nginx:1.14-alpine

Task 16

Run a container using the image name nginx:1.14-alpine and name it webapp.

Create webapp container
$ docker run -d --name webapp nginx:1.14-alpine

843c122d8ca6d21bca3c8dd915e92df4620f5127e1e4ecff1dcb92917d3ee611

Verify:

Verify webapp container
$ docker ps

CONTAINER ID   IMAGE               COMMAND                  STATUS      NAMES
843c122d8ca6   nginx:1.14-alpine   "nginx -g 'daemon..."    Up          webapp

Task 17

Cleanup: Delete all images on the host.

Remove containers if necessary.

Step 1: Stop all running containers

DOCKER
docker rm -f $(docker ps -q)

Step 2: Remove all images

DOCKER
docker rmi -f $(docker images -aq)

Step 3: Verify cleanup

Verify image cleanup
$ docker images

REPOSITORY   TAG   IMAGE ID   CREATED   SIZE

Nerdsid.com

Links
  • Home
  • Contact
  • About
  • Posts
  • Journal
  • Quotes
  • Links worth your time
  • Notes
  • Style guide
© 2026 Sidharth R.
All content on this website is licensed under CC BY-NC-SA 4.0.