DevOps Manual Set up - Set 2 Flashcards
What are the differences between virtual machines and docker?
VMs emulate complete OS environments, consuming more resources but providing stronger isolation. Docker uses lightweight containers, sharing the host OS for efficiency, portability, and rapid deployment with slightly less isolation.
What is a container?
It’s a lightweight package encapsulating an application and its environment, ensuring consistent execution across systems.
It isolates software, providing resource efficiency compared to virtual machines.
What is a Docker image?
It’s a blueprint containing the instructions for creating a docker container. It contains the application’s code, runtime environment, dependencies, libraries, tools, configurations, and settings.
- It’s a read-only template
- It’s used to create consistent and isolated containers for applications.
Describe the docker architecture
Docker’s client-server architecture comprises the Docker client communicating with the Docker daemon. The daemon manages containers, using images from registries. Docker Compose defines multi-container apps, with Swarm and Kubernetes offering orchestration.
What is Docker Compose?
It’s a tool that orchestrates multi-container Docker applications through a YAML configuration (config) file, defining and managing their execution efficiently.
It manages services, networks, volumes, and facilitates the development workflow, especially in microservices architectures.
What is the Docker Client?
The Docker client is the primary user interface for Docker, providing a command-line interface (CLI) to interact with the Docker daemon. It sends commands via the Docker API, supports remote interactions, and can be customized and extended.
What is the Docker Daemon?
The Docker daemon (dockerd) is Docker’s core process, managing container lifecycles. Users interface via the CLI or API, while the daemon handles tasks like communication with registries, networking, storage, security, and monitoring of containers.
This API is what the Docker CLI interacts with, but other tools can also use this API to communicate with the daemon.
What is a docker Registry?
It’s a storage system for Docker images, facilitating storage, sharing and distribution. Docker Hub is the default public registry, but private registries exist for controlled storage.
What is a container image builder technology?
It facilitates the creation of container images from application code and dependencies, often without needing manual Dockerfile management or a Docker daemon.
Examples: Dockerfile for Docker, Buildah, Jib (Java), and Podman - each streamlining container image creation differently
What is Jib?
Jib is a tool for creating container images for Java apps without a Dockerfile or Docker daemon. It offers reproducible builds, optimized layering, and integrates with Maven and Gradle, ensuring easy and consistent containerization.
Container Image Builder Technology
Top 10 most used docker commands:
- docker pull: Fetches an image from a registry.
- docker images: Displays a list of downloaded images.
- docker build: Builds a Docker image from a Dockerfile.
- docker run: Creates and starts a new container based on an image.
- docker ps: Lists all running containers.
- docker stop: Halts a running container.
- docker exec: Executes a command inside a running container.
- docker rm: Removes one or more containers.
- docker-compose: Manages multi-container applications using a YAML file.
- docker logs: Displays logs from a container.
What are the advantages of Jib?
- No Docker Daemon Required: Jib builds container images without relying on Docker, streamlining the build process especially in CI/CD environments.
- Reproducible Builds: Jib guarantees consistent container images for the same source code, ensuring traceability and reliability.
- Optimized Layering: Jib smartly layers Java applications, improving Docker’s caching mechanism for faster subsequent builds.
- Easy Integration: With plugins for Maven and Gradle, Jib effortlessly integrates into existing Java build processes.
What are the steps to containerize a Spring Boot application without Jib?
- Create a
Dockerfile
in the root directory with a Java base image.
– Dockerfile content anticipates the name of the JAR file to be generated by the Maven build process. - Build the application (mvn package).
–mvn clean package
– This will generate the your-spring-boot-app.jar in the target directory of your Spring Boot project. - Build Docker image (docker build).
–docker build -t my-spring-boot-app:v1
.
– This command creates a Docker image tagged as my-spring-boot-app:latest. - Run container locally (docker run):
–docker run -p 8080:8080 my-spring-boot-app:v1
– Starts a container based on the my-spring-boot-app:latest image, mapping port 8080 of the container to port 8080 on your local machine. - Login & Push to Docker registry (docker push):
–docker login
–docker push my-username/my-spring-boot-app:v1
my-spring-boot-app:v1
Is just an example name for the app.:v1
is a version specific tag to identify the image.
While using Jib in a Java project, when you do NOT need a Docker daemon?
When building images. However, to run containers from those images, a container runtime (e.g., Docker daemon) or another platform/method is required.
Assuming Jib has been properly configured, what will this command do:
mvn clean package jib:build
- mvn clean: removes previous build outputs (artifacts).
-
package:
– compiles Java code (from .java to .class bytecode files)
– tests (run unit tests)
– packages code (.class and other resources to JAR) - jib:build: containerize the application and push the Docker image to a specified registry.