Docker Flashcards

Category sponsor

Docker is an application containerization platform created by Solomon Hykes. It is a tool designed with standardization, portability, and isolation of application environments in mind. Docker is characterized by its lightness and efficiency, enabling easy packaging, distribution, and running of applications along with their dependencies across different environments. This system offers advanced container management and orchestration features, providing developers and administrators with tools for efficient deployment, scaling, and application management. Docker also supports microservice architecture and continuous integration while maintaining high performance and enabling fast and repeatable software development and deployment processes.

Our flashcard app includes carefully selected Docker interview questions with comprehensive answers that will effectively prepare you for any interview requiring Docker knowledge. IT Flashcards is not just a tool for job seekers - it's a great way to reinforce and test your knowledge, regardless of your current career plans. Regular use of the app will help you stay up-to-date with the latest Docker trends and keep your skills at a high level.

Sample Docker flashcards from our app

Download our app from the App Store or Google Play to get more free flashcards or subscribe for access to all flashcards.

What are the main differences between a container and a virtual machine?

Containers and virtual machines (VMs) differ in both architecture and performance.

1. Architecture:
A virtual machine contains a full operating system, with its own kernel, applications and libraries, which are run on a hypervisor. The hypervisor manages the sharing of hardware resources by the VM. Since the virtual machine contains a full operating system, it is larger in terms of disk size.

On the other hand, containers share the operating system's kernel they are run on and contain only the applications and their dependencies. They are managed by a container engine, like Docker. Containers are smaller and have lesser overheads, as they do not require a full operating system.

2. Performance:
Virtual machines have greater overheads, as they have to run a full operating system. This affects performance, both during startup and while running.

Containers have lesser overheads, are lighter and faster to startup, and deployment is also simpler, as they can be easily moved between environments.

Finally, both containers and virtual machines have their place in application development and both technologies are often used together in application architectures. However, the absence of separate operating systems makes containers less isolated and potentially less secure than virtual machines.

What is a Docker image and how is it used?

A Docker image, also known as Docker image, is an immutable file containing configured software. A Docker image is created based on a Dockerfile, which provides instructions on how to build the image.

The main component of a Docker image are layers. Each line of instructions in Dockerfile creates a new layer. Layers are stacked on top of each other, thus forming the final image.

A Docker image is used to run a Docker container. A container is an instance of an image running as a process. In contrast to an image, a container has a state and can be modified.

Because Docker images are immutable and contain all necessary dependencies, they can easily be transferred between various systems and servers. As a result, applications running on Docker images are always identical, regardless of the environment, which simplifies testing and deployment.

One of the key principles of Docker is the so-called "build once, run anywhere", which means that an image built once can be run on any system supporting Docker.

How does Docker use layers in container images?

Docker utilizes the concept of layers to assemble container images. Each instruction in a Dockerfile creates a new layer in the image that adds, modifies, or removes files from the previous layer.

Docker layers are read-only, which means they can't be modified after they're created. When a container is launched, Docker adds a writable layer on top of the stacked layers. All changes in the container, such as saving new files, modifying existing ones, or deleting files, are made in this writable layer.

Thanks to the use of the layering system, Docker can efficiently share and store images. When images are pulled, Docker retrieves each layer that it doesn't yet have in its cache. When images are created and saved, Docker reuses layers that are already available, significantly saving space.

The code below shows how each instruction in a Dockerfile creates a new layer:
# Using Base Image
FROM python:3.8

# Creates a layer
RUN pip install flask 

# Adds another layer.
COPY . /app

In this example, we're using the python:3.8 image as the base layer. Then we add more layers by installing the Flask package and copying files. Each of these operations adds a new layer to the image.

What is a Dockerfile and what is it used for?

A Dockerfile is a text file that contains instructions (commands) that are automatically executed when we build a Docker image. In this file, we sequentially place all the necessary information to create the image.

When we want to create an image using a Dockerfile, we need to run the following command in a specific folder:
docker build .

In this case, the dot indicates that the building context (i.e., the place where Docker looks for the Dockerfile) is the current location (folder) we are in.

The beauty of this solution is that after defining the image in the Dockerfile, we can fully recreate it on any server where Docker is installed. Regardless of host configuration, we ensure the repeatability of our development and production environments.

Here's an example Dockerfile content:
# The base image used
FROM python:3

# Set the working directory in the container
WORKDIR /usr/src/app

# Copy requirement files and install dependencies
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the code to the WORKDIR
COPY . .

# Publish the port where our application will run
EXPOSE 8080

# The command that will be run when the container starts
CMD [ "python", "./app.py" ]


The application should now be available at localhost:8080.

Download IT Flashcards App Now

Expand your Docker knowledge with our flashcards.
From basic programming principles to mastering advanced technologies, IT Flashcards is your passport to IT excellence.
Download now and unlock your potential in today's competitive tech landscape.