Containers
General 13 questions
- #1Create Images on The Fly
Requirements
Have at least one image locally (run
podman image lsto confirm).
If you don't have images locally, run simplypodman pull nginx:alpine.Objectives
- Run a container using a web server image (e.g. httpd, nginx, ...)
- Bind container's port 80 to local port 80
- Run it in detached mode
- Name should nginx_container
- Verify the web server runs and accessible
- Create an HTML file with the following content and copy it to the container to the container to path where it will be accessed as an index file
<html> <head> <title>It's a me</title> </head> <body> <h1>Mario</h1> </body>- Create an image out of the running container and call it "nginx_mario"
- Tag the container with "mario" tag
- Remove the original container (container_nginx) and verify it was removed
- Create a new container out of the image you've created (the same way as the original container)
- Run
curl 127.0.0.1:80. What do you see? - Run
podman diffon the new image. Explain the output
Solution
- #2Containerized DB
- Run a container with a database of any type of you prefer (MySql, PostgreSQL, Mongo, etc.)
- Verify the container is running
- Access the container and create a new table (or collection, depends on which DB type you chose) for students
- Insert a row (or document) of a student
- Verify the row/document was added
- #3Containerized DB with Persistent Storage
- Run a container with a database of any type of you prefer (MySql, PostgreSQL, Mongo, etc.)
- Use a mount point on the host for the database instead of using the container storage for that
- Explain why using the host storage instead of the container one might be a better choice
- Verify the container is running
- #4Containerized Web Server
- Run a containerized web server in the background and bind its port (8080) to a local port
- Verify the port (8080) is bound
- Reach the webserver from your local host
- Now run the same web application but bound it to the local port 8080
- #5Layer by Layer
Objective
Learn about image layers
Requirements
Make sure Docker is installed on your system and the service is started
# Fedora/RHEL/CentOS rpm -qa | grep docker systemctl status dockerInstructions
- Write a Dockefile. Any Dockefile! :) (just make sure it's a valid one)
- Build an image using the Dockerfile you've wrote
- Which of the instructions you've used, created new layers and which added image metadata?
- What ways are there to confirm your answer to the last question?
- Can you reduce the size of the image you've created?
- #6Multi-Stage Builds
Objective
Learn about multi-stage builds
Instructions
- Without actually building an image or running any container, use the following Dockerfile and convert it to use multi-stage:
FROM nginx RUN apt-get update \ && apt-get install -y curl python build-essential \ && apt-get install -y nodejs \ && apt-get clean -y RUN mkdir -p /my_app ADD ./config/nginx/docker.conf /etc/nginx/nginx.conf ADD ./config/nginx/k8s.conf /etc/nginx/nginx.conf.k8s ADD app/ /my_cool_app WORKDIR /my_cool_app RUN npm install -g ember-cli RUN npm install -g bower RUN apt-get update && apt-get install -y git \ && npm install \ && bower install \ RUN ember build — environment=prod CMD [ “/root/nginx-app.sh”, “nginx”, “-g”, “daemon off;” ]- What are the benefits of using multi-stage builds?
- #7Run, Forest, Run!
Objective
Learn what restart policies do and how to use them
Requirements
Make sure Docker is installed on your system and the service is started
# Fedora/RHEL/CentOS rpm -qa | grep docker systemctl status dockerInstructions
- Run a container with the following properties:
- image: alpine
- name: forest
- restart policy: always
- command to execute: sleep 15
- Run
docker container ls- Is the container running? What about after 15 seconds, is it still running? why? - How then can we stop the container from running?
- Remove the container you've created
- Run the same container again but this time with
sleep 600and verify it runs - Restart the Docker service. Is the container still running? why?
- Update the policy to
unless-stopped - Stop the container
- Restart the Docker service. Is the container running? why?
- #8Running Containers
Objective
Learn how to run, stop and remove containers
Requirements
Make sure Podman or Docker (or any other containers engine) is installed on your system
Instructions
- Run a container using the latest nginx image
- List the containers to make sure the container is running
- Run another container but this time use ubuntu latest and attach to the terminal of the container
- List again the containers. How many containers are running?
- Stop the containers
- Remove the containers
- #9Sharing Images
Requirements
Have at least one image locally (run
podman image lsto confirm).
If you don't have images locally, run simplypodman pull httpd.Objectives
- Choose an image and create an archive out of it
- Check the archive size. Is it different than the image size? If yes, what's the difference? If not, why?
- Copy the generated archive to a remote host
- Load the image
- Verify it was loaded and exists on the remote host
Solution
- #10Working with Images
Objective
Learn how to work with containers images
Requirements
Make sure Podman or Docker (or any other containers engine) is installed on your system
Instructions
- List the containers images in your environment
- Pull the latest ubuntu image
- Run a container with the image you just pulled
- Remove the image. Did it work?
- Do whatever is needed in order to remove the image
- #11You’re a DevOps engineer deploying a Node.js application using Docker. You run
docker run -d -p 3000:3000 my-node-app, but the container exits immediately. Usingdocker ps -a, you see the container status asExited. How would you troubleshoot and resolve this issue? - #12As a DevOps engineer, you need to deploy a web application with a Node.js backend and a MySQL database using Docker. The Node.js app connects to MySQL on
localhost:3306, but runningdocker runfor each container separately fails because they can’t communicate. How would you set up these containers to work together? - #13You’re a DevOps engineer integrating a Dockerized Python application into a Jenkins CI/CD pipeline. The Dockerfile builds slowly, causing pipeline delays. How would you optimize the Dockerfile to speed up builds while maintaining functionality?
Containers 101 7 questions
- #14What is a Container?
- #15Why containers are needed? What is their goal?
- #16What is a container image?
- #17How are containers different from virtual machines (VMs)?
- #18In which scenarios would you use containers and in which you would prefer to use VMs?
- #19Describe the process of containerizing an application
- #20What are some of the advantages in using containers? you can compare to other options like VMs
Commands Commands 14 questions
- #21How to run a container?
- #22Why after running podman container run ubuntu the output of podman container ls is empty?
- #23How to list all the containers on the local host?
- #24How to attach your shell to a terminal of a running container?
- #25True or False? You can remove a running container if it doesn't running anything
- #26How to stop and remove a container?
- #27What happens when you run docker container run ubuntu?
- #28How to run a container in the background?
- #29If you'll run sleep 100 inside a container, will you see it when listing all the processes of the host on which the container runs? Why?
- #30True or False? If image httpd-service has an entry point for running the httpd service then, the following will run the container and eventually the httpd service podman run httpd-service ls
- #31True or False? Running podman restart CONTAINER_NAME kills the main process inside the container and runs it again from scratch
- #32You would like to run a web server inside a container but, be able to access it from the localhost. Demonstrate how to do that
- #33After running a container, it stopped. podman ps shows nothing. How can you show its details?
- #34How to list all the image tags for a given container image?
Images 64 questions
- #35Why container images are relatively small?
- #36You are interested in running a container with snake game application. How can you search for such image and check if it exists?
- #37How to list the container images on certain host?
- #38How to download/pull a container image without actually running a container?
- #39True or False? It's not possible to remove an image if a certain container is using it
- #40True or False? If a tag isn't specified when pulling an image, the 'latest' tag is being used
- #41True or False? Using the 'latest' tag when pulling an image means, you are pulling the most recently published image
- #42Where pulled images are stored?
- #43Explain container image layers
- #44True or False? Changing the content of any of the image layers will cause the hash content of the image to change
- #45How to list the layers of an image?
- #46True or False? In most cases, container images contain their own kernel
- #47True or False? A single container image can have multiple tags
- #48What is a dangling image?
- #49How to see changes done to a given image over time?
- #50What
podman commitdoes?. When will you use it? - #51True or False? Multiple images can share layers
- #52What is the digest of an image? What problem does it solves?
- #53True or False? A single image can support multiple architectures (Linux x64, Windows x64, ...)
- #54What is a distribution hash in regards to layers?
- #55How multi-architecture images work? Explain by describing what happens when an image is pulled
- #56How to check which architectures a certain container image supports?
- #57How to check what a certain container image will execute once we'll run a container based on that image?
- #58How to view the instructions that were used to build image?
- #59How docker image build works?
- #60What is the role of cache in image builds?
- #61How to remove an image from the host?
- #62What ways are there to reduce container images size?
- #63What are the pros and cons of squashing images?
- #64You would like to share an image with another developer, but without using a registry. How would you do it?
- #65True or False? Once a container is stopped and removed, its image removed as well from the host
- #66How to view the instructions that were used to build image?
- #67How to find out which files were added to the container image filesystem?
- #68True or False? podman diff works only on the container filesystem and not mounted files
- #69How the centralized location, where images are stored, is called?
- #70What is a Registry?
- #71A registry contains one or more ____ which in turn contain one or more ____
- #72How to find out which registry do you use by default from your environment?
- #73How to configure registries with the containers engine you are using?
- #74How to retrieve the latest ubuntu image?
- #75How to push an image to a registry?
- #76What are some best practices in regards to Container Images?
- #77What ways are there for creating new images?
- #78What are image tags? Why is it recommended to use tags when supporting multiple releases/versions of a project?
- #79How to tag an image?
- #80True or False? Once created, it's impossible to remove a tag for a certain image
- #81True or False? Multiple tags can reference the same image
- #82What is a Containerfile/Dockerfile?
- #83What instruction exists in every Containerfile/Dockefile and what does it do?
- #84List five different instructions that are available for use in a Containerfile/Dockerfile
- #85What are some of the best practices regarding Containerfiles/Dockerfiles that you are following?
- #86What is the "build context"?
- #87What is the difference between ADD and COPY in Containerfile/Dockerfile?
- #88What is the difference between CMD and RUN in Containerfile/Dockerfile?
- #89How to create a new image using a Containerfile/Dockerfile?
- #90Do you perform any checks or testing on your Containerfiles/Dockerfiles?
- #91Which instructions in Containerfile/Dockerfile create new layers?
- #92Which instructions in Containerfile/Dockerfile create image metadata and don't create new layers?
- #93Is it possible to identify which instruction create a new layer from the output of podman image history?
- #94True or False? Each Containerfile instruction runs in an independent container using an image built from every previous layer/entry
- #95What's the difference between these two forms:
ENTRYPOINT ["cmd", "param0", "param1"] CMD ["param0"] ENTRYPOINT cmd param0 param1 CMD param0 - #96Containerfile/Dockerfile can contain more than one ENTRYPOINT instruction and one CMD instruction
- #97What happens when CMD instruction is defined but not an ENTRYPOINT instruction in a Containerfile/Dockerfile?
- #98In the case of running podman run -it IMAGE ls the ls overrides the ___ instruction
Storage 5 questions
- #99Container storage is said to be ephemeral. What does it mean?
- #100True or False? Applications running on containers, should use the container storage to store persistent data
- #101You stopped a running container but, it still uses the storage in case you ever resume it. How to reclaim the storage of a container?
- #102How to create a new volume?
- #103How to mount a directory from the host to a container?
Architecture 6 questions
- #104How container achieve isolation from the rest of the system?
- #105What Linux kernel features does containers use?
- #106Describe in detail what happens when you run
podman/docker run hello-world? - #107Describe difference between cgroups and namespaces
- #108Which of the following are Linux features that containers use?
- cspaces
- namegroups
- namespaces
- cgroups
- ELlinux
- SElinux
- #109True or False? Containers have ephemeral storage layer
Docker Architecture 22 questions
- #110Which components/layers compose the Docker technology?
- #111What components are part of the Docker engine?
- #112What is the low-level runtime?
- #113What is the high-level runtime?
- #114True or False? The docker daemon (dockerd) performs lower-level tasks compared to containerd
- #115Describe in detail what happens when you run
docker pull image:tag? - #116Describe in detail what happens when you run a container
- #117True or False? Killing the Docker daemon will kill all the running containers
- #118True or False? containerd forks a new instance runc for every container it creates
- #119True or False? Running a dozen of containers will result in having a dozen of runc processes
- #120What is shim in regards to Docker?
- #121How would you transfer data from one container into another?
- #122What happens to data of the container when a container exists?
- #123How do you remove old, non running, containers?
- #124How the Docker client communicates with the daemon?
- #125Explain Docker interlock
- #126What is Docker Repository?
- #127Explain image layers
- #128What best practices are you familiar related to working with containers?
- #129How do you manage persistent storage in Docker?
- #130How can you connect from the inside of your container to the localhost of your host, where the container runs?
- #131How do you copy files from Docker container to the host and vice versa?
Docker Compose 5 questions
- #132Explain what is Docker compose and what is it used for
- #133Describe the process of using Docker Compose
- #134Explain Multi-stage builds
- #135True or False? In multi-stage builds, artifacts can be copied between stages
- #136What .dockerignore is used for?
Networking 1 question
- #137What container network standards or architectures are you familiar with?
Docker Networking 4 questions
- #138What network specification Docker is using and how its implementation is called?
- #139Explain the following blocks in regards to CNM:
- Networks
- Endpoints
- Sandboxes
- Networks
- #140True or False? If you would like to connect a container to multiple networks, you need multiple endpoints
- #141What are some features of libnetwork?
Security 2 questions
- #142What security best practices are there regarding containers?
- #143A container can cause a kernel panic and bring down the whole host. What preventive actions can you apply to avoid this specific situation?
Docker in Production 9 questions
- #144What are some best practices you following in regards to using containers in production?
- #145True or False? It's recommended for production environments that Docker client and server will communicate over network using HTTP socket
- #146What forms of self-healing options available for Docker containers?
- #147What restart policies are you familiar with?
- #148Explain Rootless Containers
- #149Are there disadvantages in running rootless containers?
- #150Give one example of rootless containers are more safe from security perspective
- #151When running a container, usually a virtual ethernet device is created. To do so, root privileges are required. How is it then managed in rootless containers?
- #152When running a container, usually a layered file system is created, but it requires root privileges. How is it then managed in rootless containers?
OCI 2 questions
- #153What is the OCI?
- #154Which operations OCI based containers must support?
Scenarios 2 questions
- #155There is a running container that has a certain issue. You would like to share an image of that container with your team members, with certain environment variables set for debugging purposes. How would you do it?
- #156You and your team work on the same project, but different versions of it. For each version, the team creates a new, separate image. What would you suggest the team to change in such case?