Skip to Content
Certified Kubernetes Application Developer (CKAD) Study Guide, 2nd Edition
book

Certified Kubernetes Application Developer (CKAD) Study Guide, 2nd Edition

by Benjamin Muschko
May 2024
Intermediate to advanced content levelIntermediate to advanced
366 pages
7h 43m
English
O'Reilly Media, Inc.
Content preview from Certified Kubernetes Application Developer (CKAD) Study Guide, 2nd Edition

Appendix A. Answers to Review Questions

Chapter 4, Containers

  1. The given Dockerfile builds a nodejs-based application. All files necessary to run the application are available in the same directory. Upon further inspection, you will find that the Dockerfile exposes port 3000.

    Build the container image with the following command:

    $ docker build -t nodejs-hello-world:1.0.0 .
    

    You will be able to find the container image by listing it:

    $ docker images
    REPOSITORY           TAG     IMAGE ID       CREATED          SIZE
    nodejs-hello-world   1.0.0   0cc723ca8b06   15 seconds ago   180MB
    

    Run the container in detached mode with the following command. Make sure to map port 80 to the exposed container port 3000:

    $ docker run -d -p 80:3000 nodejs-hello-world:1.0.0
    9e0f1abcef415e902422117de7644544cdd08ae158a1cd0b2a2d182fcf056cab
    

    You can discover details about the container by listing them:

    $ docker container ls
    CONTAINER ID   IMAGE                      COMMAND                  ...
    9e0f1abcef41   nodejs-hello-world:1.0.0   "docker-entrypoint.s…"   ...
    

    You can now access the application on port 80 with either curl or wget:

    $ curl localhost
    Hello World
    $ wget localhost
    
    --2023-05-09 08:38:30--  http://localhost/
    Resolving localhost (localhost)... ::1, 127.0.0.1
    Connecting to localhost (localhost)|::1|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    ...
    2023-05-09 08:38:30 (2.29 MB/s) - ‘index.html’ saved [12/12]
    

    You can retrieve logs written by the application with the following command:

    $ docker logs 9e0f1abcef41
    Magic happens on port 3000
    
  2. Change ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Certified Kubernetes Application Developer (CKAD) Study Guide

Certified Kubernetes Application Developer (CKAD) Study Guide

Benjamin Muschko

Publisher Resources

ISBN: 9781098152857Errata PageSupplemental Content