Docker Basics Quiz
46 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which command is used to build a Docker image?

  • docker images
  • docker build --tag (correct)
  • docker run --name
  • docker ps
  • A container can be created without an image.

    False (B)

    What is a Dockerfile used for?

    To automate the process of Docker image creation.

    An image in Docker contains executable application source code as well as all the necessary ______ required to run the application.

    <p>dependencies</p> Signup and view all the answers

    Match the following Docker commands with their functions:

    <p>docker build --tag = Build a new image docker run --name = Run a container with a specific name docker images = List available images docker ps = List running containers</p> Signup and view all the answers

    What is the primary purpose of a Docker image?

    <p>To contain all files and dependencies needed to run an application (D)</p> Signup and view all the answers

    Docker containers have access to all files on the host machine.

    <p>False (B)</p> Signup and view all the answers

    Which base image is used in the example Dockerfile for the toy.py app?

    <p>python:alpine3.17</p> Signup and view all the answers

    What is the purpose of a Dockerfile?

    <p>To create a new image by specifying changes to an existing image (A)</p> Signup and view all the answers

    Containers have a shared file system that allows for modification by any container using the same image.

    <p>False (B)</p> Signup and view all the answers

    What layer of the file system contains modifications made by a container?

    <p>writeable container layer</p> Signup and view all the answers

    Docker images are built using a ______________ file system.

    <p>union</p> Signup and view all the answers

    Match the following components of Docker with their descriptions:

    <p>Image = Read-only layer used to create containers Container = Running instance of an image with its own filesystem Dockerfile = Recipe for building new images Union filesystem = Method for merging multiple file systems</p> Signup and view all the answers

    Which of the following is NOT a benefit of using Docker containers?

    <p>Automatic scaling of applications (A)</p> Signup and view all the answers

    The metadata of a Docker image includes information like exposed ports and environment variables.

    <p>True (A)</p> Signup and view all the answers

    What allows for easy modification of existing images in Docker?

    <p>layering and copy-on-write</p> Signup and view all the answers

    What is the purpose of the command 'RUN pip install Flask' in a Dockerfile?

    <p>To install the Flask package into the Docker container (D)</p> Signup and view all the answers

    The command 'EXPOSE 8001' indicates that the container should listen on port 8001.

    <p>True (A)</p> Signup and view all the answers

    What environment variable is set to indicate the main application file in this Dockerfile?

    <p>FLASK_APP</p> Signup and view all the answers

    The command 'CMD ["flask", "run", "--host=0.0.0.0"]' is used to ________.

    <p>start the Flask application</p> Signup and view all the answers

    Match the Dockerfile command with its function:

    <p>FROM python:alpine3.17 = Base image WORKDIR ./app = Set working directory COPY toys.py = Copy application file ENV FLASK_RUN_PORT=8001 = Set environment variable</p> Signup and view all the answers

    What does the 'COPY toys.py' command do?

    <p>Copies the toys.py file from the host machine to the container (B)</p> Signup and view all the answers

    The container's working directory is set to './app' using the WORKDIR instruction.

    <p>True (A)</p> Signup and view all the answers

    What command does the Dockerfile execute when the container starts?

    <p>flask run --host=0.0.0.0</p> Signup and view all the answers

    What is Docker Hub primarily used for?

    <p>Storing and distributing Docker images (D)</p> Signup and view all the answers

    A Docker registry can only hold public images.

    <p>False (B)</p> Signup and view all the answers

    What command is used to push an image to a Docker registry?

    <p>docker push</p> Signup and view all the answers

    Docker images are organized in a Docker ______ which holds all the versions of a specific image.

    <p>repository</p> Signup and view all the answers

    Match the following Docker concepts with their descriptions:

    <p>Docker Images = Executable packages that include everything needed to run an application Docker Registry = A storage and distribution system for Docker images Docker Hub = A public registry for Docker images Docker Trusted Registry = A commercially supported version of the Docker registry</p> Signup and view all the answers

    Which of the following is a true statement about Docker Engine?

    <p>It provides a REST API for interacting with the Docker system. (B)</p> Signup and view all the answers

    Docker is configured to look for images on Docker Hub by default.

    <p>True (A)</p> Signup and view all the answers

    What is the purpose of data volumes in Docker?

    <p>To persist data and share it between containers</p> Signup and view all the answers

    What is a benefit of using Docker for CI/CD processes?

    <p>Facilitates automation of processes (A)</p> Signup and view all the answers

    Docker always prevents dependency conflicts when importing multiple packages into a single container.

    <p>False (B)</p> Signup and view all the answers

    What is a common command used to start services in Docker Compose?

    <p>Compose Up</p> Signup and view all the answers

    Docker containers are designed to have a __________ responsibility and use a few integrated packages.

    <p>single</p> Signup and view all the answers

    What might happen if you update a Dockerfile based on an image tagged 'latest'?

    <p>It may break the previous working image. (C)</p> Signup and view all the answers

    Using the latest version of packages in Docker images guarantees that all vulnerabilities are patched.

    <p>False (B)</p> Signup and view all the answers

    Name one reason why dependency conflicts can occur in Docker containers.

    <p>Importing multiple packages</p> Signup and view all the answers

    What does the --publish (-p) flag do in Docker commands?

    <p>Maps the host's port to the container's port. (C)</p> Signup and view all the answers

    Docker containers have their own isolated file system and do not have access to the host's file system.

    <p>False (B)</p> Signup and view all the answers

    What is the primary purpose of tagging a Docker image?

    <p>To give a specific version or name to the image for easier reference.</p> Signup and view all the answers

    A unique ID is assigned to every ______ created in Docker.

    <p>image</p> Signup and view all the answers

    Which command would you use to list all existing Docker images in the local registry?

    <p>docker images (B)</p> Signup and view all the answers

    A Docker container can be created without specifying a Docker image.

    <p>False (B)</p> Signup and view all the answers

    What is the significance of using a unique prefix for an image ID in Docker commands?

    <p>It allows Docker to identify the image unambiguously without using the full ID.</p> Signup and view all the answers

    Flashcards

    Docker Image

    A complete package containing all the components needed to make an application run as a container, including code, libraries, and dependencies.

    Docker Container

    A running instance of a Docker image, isolated and containing the application and all its dependencies. It's like a little 'virtual machine' for your app.

    Dockerfile

    A text file with instructions that automate the process of building a Docker image. It defines the steps for building a container environment.

    Docker Hub

    A cloud-based registry where you can store, manage, and share Docker images.

    Signup and view all the flashcards

    Docker build

    A command that takes a Dockerfile and builds a Docker image from it, assembling the application environment.

    Signup and view all the flashcards

    Docker run

    A command that starts a new Docker container from an image, running the application within it.

    Signup and view all the flashcards

    Docker Images: Layers

    Docker images are built in layers, each containing a specific set of instructions or changes. This makes efficient use of disk space and allows for sharing parts of images.

    Signup and view all the flashcards

    Docker ps

    A command used to list all currently running Docker containers on the system.

    Signup and view all the flashcards

    FROM

    The first command in a Dockerfile, specifying the base image to use. The Dockerfile builds on top of this base image.

    Signup and view all the flashcards

    RUN

    This command executes a command inside the container during the build process. It adds a layer to the image.

    Signup and view all the flashcards

    WORKDIR

    Sets the working directory inside the container where subsequent commands will be executed. This keeps your container organized.

    Signup and view all the flashcards

    COPY

    This command copies files from the host machine (your computer) into the Docker container.

    Signup and view all the flashcards

    ENV

    This command sets environment variables inside the container. These variables store information like names, passwords, and API keys.

    Signup and view all the flashcards

    EXPOSE

    This command tells Docker to expose ports on the container. This allows other containers or your host machine to connect to the container.

    Signup and view all the flashcards

    CMD

    This command defines the default command to execute when the container starts. This is like the main function of your application.

    Signup and view all the flashcards

    Union File System

    A layered file system that combines the read-only image layers with a writable container layer. It allows containers to share files from the image while providing isolated writable layers for each container's modifications.

    Signup and view all the flashcards

    Writeable Container Layer

    The topmost layer in the union file system, where a container stores its own changes, such as new files, modifications, or deletions. It's isolated and only visible to the specific container.

    Signup and view all the flashcards

    Copy-on-Write

    A technique used in union file systems where a container creates a private copy of a modified file instead of directly altering the shared image layer. This preserves the original image and keeps containers independent.

    Signup and view all the flashcards

    How does the union file system help avoid dependency conflicts?

    Each container has its own isolated filesystem, allowing different versions of dependencies to coexist without conflicts. This enables running multiple applications with different dependency needs within the same system.

    Signup and view all the flashcards

    What does a Docker image consist of?

    A Docker image contains a filesystem, metadata, and a startup command. Metadata includes information like exposed ports, environment variables, and other configuration settings.

    Signup and view all the flashcards

    What is a Dockerfile?

    A text file containing instructions for building a Docker image. It specifies the base image, commands to modify the image, and the startup command for the container.

    Signup and view all the flashcards

    What is the purpose of a Docker container?

    A Docker container is a runtime instance of a Docker image, providing a fully isolated environment with its own filesystem and system settings. It executes the image's startup command and runs the application.

    Signup and view all the flashcards

    What is the difference between a Docker image and a Docker container?

    A Docker image is a read-only template that defines the structure and content of a container. A Docker container is a running instance of an image, with access to its filesystem and the ability to execute commands.

    Signup and view all the flashcards

    Docker Engine

    The core of Docker, it manages and runs Docker containers on your machine. It interacts with the Docker registry to get images and handles container creation, execution, and lifecycle.

    Signup and view all the flashcards

    Docker Registry

    A storage and distribution system for Docker images. It allows you to store, retrieve, and manage Docker images.

    Signup and view all the flashcards

    Docker Repository

    A collection of all versions (tags) of a specific image within a Docker registry.

    Signup and view all the flashcards

    Docker Image Tag

    A label or version identifier used for a specific image in a repository. Multiple tags can point to the same image with different versions.

    Signup and view all the flashcards

    Docker Pull Command

    This command retrieves a Docker image from a registry, either local or remote, and stores it on your machine.

    Signup and view all the flashcards

    Docker Push Command

    This command uploads a locally built Docker image to a registry for sharing or long-term storage.

    Signup and view all the flashcards

    Private Docker Registry

    A secure, controlled registry used to manage internal or proprietary Docker images within an organization.

    Signup and view all the flashcards

    Docker Compose Up

    Starts and runs all services defined in a docker-compose.yml file, creating and starting containers based on specified images.

    Signup and view all the flashcards

    Docker Compose Down

    Stops and removes all containers, networks, and images created by docker-compose.

    Signup and view all the flashcards

    Docker Compose Stats

    Provides real-time resource usage information for running services defined by docker-compose.

    Signup and view all the flashcards

    Docker Volumes

    Persistent storage mechanisms that allow data to be shared between containers or even the host machine.

    Signup and view all the flashcards

    Single Responsibility in Containers

    A principle where each container runs a specific task or service, minimizing dependency conflicts.

    Signup and view all the flashcards

    Dockerfile Updates and Image Breakage

    Changes to a Dockerfile, especially using 'latest' tags, can cause previously working containers to fail.

    Signup and view all the flashcards

    Testing Docker Images

    It's essential to test updated Docker images after making changes, ensuring they work as expected.

    Signup and view all the flashcards

    Study Notes

    Topic 3: Containers - Part 1

    • These slides are the property of Dr. Daniel Yellin and intended for use only by students in the class. Distribution or posting is prohibited.

    Docker Overview

    • Docker, a tool for packaging, managing, and deploying software applications, is based on images, containers, and layers.
    • It addresses the challenge of packaging all software dependencies together and resolving conflicts that may arise when multiple applications or modules need to run on a single computer if those applications are using different versions of the same package(s).

    What Problems does Docker Solve?

    • Packaging: Bundling the application with all required dependencies into a single unit called a container. This isolates the application from the host environment and ensures consistent execution across different systems. 
    • Portability: Allowing applications to run in various environments (development, testing, and production) regardless of hardware, operating system, or configuration.
    • Independent Lifecycles: Enabling the deployment and updating of application modules independently, without impacting the entire application.

    Multiple Programs Running on top of OS

    • Diagrams explain how Docker's containers create isolated environments separated from the operating system's kernel. 
    • Running different versions of software on one machine is possible without conflicts using isolated containers.

    A Container Partitions System Resources

    • Containers isolate different applications using system resource partitioning, so different applications inside different containers cannot interact.

    What problems does Docker solve? — Portability

    • Applications frequently need to run in various environments (desktop, testing, production, cloud).
    • Docker addresses compatibility problems that emerge from different hardware and operating systems by facilitating the transport and deployment of applications without altering different version specificities for each one.
    • Docker can run multiple applications on the same server despite differing operating systems and hardware requirements.

    Heterogeneous Applications

    • Applications built using differing hardware and/or operating systems can run on a single server (given same kernel). This is possible as long as the respective packages are also consistent.

    What problems does Docker solve? — Independent lifecycle management of application modules

    • Docker enables an independent lifecycle management for different application parts or modules. 
    • When a bug is fixed or a feature added to a single module these changes can be deployed without impacting other parts of the application.
    • This promotes modularity (and single-responsibility principle) and facilitates updating and testing individual parts of the application.

    Independent lifecycle management — Example

    • Diagram showing the different team deployment stages and how this approach is effective in managing multiple-module applications.

    What problems does Docker solve? — Sharing and reusability

    • Reusing code and resources can be complex due to installation processes, error-prone build processes, and various dependencies.
    • Docker simplifies code reuse by allowing the packaging and distribution of applications (and the dependencies) without the need for the end-user to unpack/re-install or reconfigure multiple packages.
    • Using Docker, others can take code and update it without negatively impacting the original source code.

    What problems does Docker solve? — Scalability

    • Docker is a solution for scaling applications by increasing server instances (given adequate capacity) to handle the increased flow of requests. This approach can reduce costs on cloud hardware and VMs.

    Docker bridges development and deployment

    • Docker encapsulates code and dependencies. It facilitates quick, reliable, and portable applications (across operating systems) leveraging container engine services.
    • Different teams can build and deploy their parts, ensuring effective coordination.
    • Automating configuration and updates via pipelines simplifies deployment processes.

    Images

    • Images are collections of files, metadata, and a command. These contain executable application code, tools, libraries, and dependencies.
    • They are templates to create containers.

    Images and Containers

    • Containers are isolated runtime processes based on images.
    • The command, files, and metadata are accessed for the process execution.
    • The process properties are defined in metadata, such as accessible network ports.

    Dockerfiles

    • Dockerfiles are used to automate image creation process using a syntax and commands to build images.
    • These files list instructions for building images.
    • The image generation can be based on other images, using a syntax for "on-top" image construction.

    Docker by example

    • Docker provides a method for building images using images, container management, and container execution.

    4 Docker Commands

    • Summary of Docker commands, including build, run, images, and ps.

    A Dockerfile to containerize our toy.py app

    • Detailed Dockerfile instructions for packaging the toy.py application. This includes the use of FROM (to use a base image), WORKDIR to create an app directory on the image, COPY command used to copy files and RUN to execute a shell command on the image.
    • The EXPOSE command, for exposing the port 8001 in the container, is also included. 

    Dockerfile: Instructions on Making an Image

    • Detailed Dockerfile instructions with explanations for building a Docker image.

    Dockerfile: Instructions on Making an Image (detail)

    • Detailed instructions on building a Docker image with explanations for each command.

    Build Image

    • How to build the image, specifying the name and tag “toysimage:v1”
    • Identifying/Locating the Dockerfile. 

    Explaining the docker build cmd messages

    • Explanation of the detailed process of building an image to be used as a container

    Docker images

    • Finding Docker images in local image repositories using commands (to list images).

    Dockerfiles and layers

    • How instructions in Dockerfiles create layers for an image
    • Layer contents are encoded by the Dockerfile execution instructions. 
    • Other instructions modify image metadata.

    Layers in the toys container

    • Visualization of how layers combine/form the whole image 

    Looking inside an image

    • Exploring the software content/vulnerabilities using Docker SBOM command. 

    Docker Desktop, CVE Vulnerabilities

    • Showing vulnerabilities in each image layer.

    4 Docker Commands(page 28)

    • Review of Docker commands for building images, running images, listing images

    Create and run container

    • Instructions for creating and running a container using Docker commands and command parameters

    Ports and port forwarding

    • Defining ports as numeric identifiers for connecting software and services. 
    • Describing port forwarding/mapping as translating network traffic requests.

    Docker containers have their own IP addresses and ports

    • Containers have their own IP addresses (changing during re-start).
    • Containers listen on specific ports, such as 8001 for HTTP requests (API calls).
    • Clients use the host's IP address and the published port to interact with the container.

    Port publishing

    • How to publish container ports to the host's port(s).
    • How communication works (client, host, container).

    Port mapping in Docker

    • How to map container ports to host ports (in case of multiple container instances).

    Build and run container (cont)

    • How to list running and all containers (running or stopped).
    • Shows what port to use to forward requests to specific container ports

    Checking that the server is running correctly

    • How to issue requests to a RESTful server.
    • How to use Postman or curl for this testing 

    Curl requests to toys server

    • Examples of curl commands sending POST requests with various parameters (in JSON).
    • Illustrates data sent to and received from the Docker container.

    What does "docker run” really do?

    • Detailed explanation of the docker run command: finding images, creating containers, mounting file systems, and starting processes.

    Common container lifecycle commands

    • Summary of common commands associated with container lifecycle (remove, stop, start, kill, pause, unpause).

    Union File System

    • How containers share and modify images (how different layers are combined in images with a "copy-on-write" system). 

    Union file system

    • The Union File System helps manage how containers share and modify images by keeping contents separate.

    Union file system

    • Explanation of how the Union File System merges file systems while keeping the underlying structures distinct, enabling containers to share files.
    • Shows diagrammatical view of how containers reuse layers of files when images are created or modified/augmented.

    Copy-on-write

    • How changes are recorded/isolated from the main image structure. This allows for multiple containers to use the same base image without over-writing each other.

    Union file system helps avoid dependency conflicts

    • Understanding how the union file system helps prevent compatibility issues by keeping dependencies isolated among containers

    What we have learned about Docker so far

    • Summarizing the key concepts of Docker images, containers, and Dockerfiles (the recipes used to create images).


    What we have learned about Docker so far (cont)

    • A Dockerfile is a recipe for making new images.
    • Easy example using rest-word-svr.
    • Docker has a rich set of commands

    Question: Running two separate instances

    • How to run two container instances and how to address them on different ports on the host machine.

    Running two separate rest-word-svr instances

    • Steps to run two instances of the Docker image, toysimage:v1.
    • Explanation of how different containers can run parallelly, and how port publishing is essential for separate communication.

    Running two separate rest-word-svr instances cont

    • Instructions to verify the operation of two containers through different port addresses.
    • The summary image shows the running status and mapping to different hostports

    Issues requests (curl) to the two containers

    • Examples of issuing HTTP requests to each of the container instances through the appropriate Docker Host ports, demonstrating that both are operating correctly.

    Docker Architecture

    • Description of the main components comprising Docker (host machine, client, daemon, REST API, and private registry).

    Docker Architecture (cont)

    • Detailing how the Docker client connects and interacts with Docker daemon, providing images, and executing instructions.

    Docker Architecture

    • Describing the overall structure of a Docker system.

    Docker Engine provides a REST API

    • Description of Docker RESTful APIs and available commands.

    Registries and Repositories

    • Docker registries, repositories, and artifacts. They store named images and each repository may have multiple versions of the same image.

    Docker Hub and private registries

    • Features of Docker Hub and the value of private registries for security and image management.

    Docker best practices

    • Best practices for efficiently building, deploying and managing containers: using single process per container, treat containers as ephemeral entities. use pre-built images to minimize the layers.

    How to share using Docker

    • Two contrasting approaches to sharing Docker images (public repository and Dockerfile sharing).

    Docker Summary

    • Summarizing the important characteristics of Docker as a tool for modern application deployment

    Docker helps developers

    • Summarizing the benefits and functionalities of Docker as a tool for developers.

    But Docker does not solve all problems

    • Issues/challenges when using Docker, including dependency and isolation problems, image vulnerabilities, potential conflicts.

    Docker compose common commands

    • Listing common Docker compose commands for managing containers, images, and volumes.

    References

    • Providing the list of resources used for this lesson. This includes the links (URLs) to articles, pages, books, and documents used to develop the lesson.

    Additional reference material

    • List of links containing additional resources to learn more about Docker. This should guide users seeking additional resources/information.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Test your knowledge of Docker with this quiz covering essential concepts such as images, containers, and Dockerfiles. Assess your understanding of command usage, file systems, and the purpose of Docker components. Perfect for beginners looking to solidify their Docker skills.

    More Like This

    Use Quizgecko on...
    Browser
    Browser