change dir name orch,container

This commit is contained in:
2025-10-04 09:53:08 +03:30
parent 1c472e4b94
commit 6beeea3e5c
43 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
# Docker Overview
## What is Docker?
[Docker](https://www.docker.com/) is an open-source platform that streamlines the development, shipping, and deployment of applications using containers. Containers are lightweight, self-contained environments that bundle everything required to run an application, including code, runtime, libraries, and dependencies. By using Docker, developers can ensure that applications run consistently across different environments, whether in development, testing, or production.
## Core Docker Concepts
### Stateless vs. Stateful Applications
- **Stateless**: These applications do not retain user data between sessions. For example, web servers like Nginx are typically stateless, as they dont need to save any data between requests.
- **Stateful**: These applications retain data across sessions, which means they store information that can be retrieved later. Databases are common examples of stateful applications.
## Key Docker Components
### Docker Images
A Docker image is a read-only template that defines the environment in which your application runs. It includes the application code, along with all necessary runtime components, libraries, and dependencies. Images are created using a Dockerfile—a script that automates the process of setting up the environment. Once an image is built, it can be used to create one or more containers.
### Docker Containers
A Docker container is a runnable instance of an image. It encapsulates everything the application needs to run, ensuring isolation from the host system and other containers. Containers are highly portable and can be moved across different environments without affecting their functionality. This makes them ideal for developing, testing, and deploying applications in a consistent manner.
### Dockerfile
A Dockerfile is a simple text file that contains a set of instructions for building a Docker image. These instructions specify the base image to use, the environment variables, dependencies, and commands required to assemble the application environment. By defining these steps in a Dockerfile, developers can automate the image creation process, ensuring that the application behaves the same way in every environment.
### Docker Hub
[Docker Hub](https://hub.docker.com/) is a centralized cloud-based repository service where Docker images are stored, shared, and managed. It allows developers to pull pre-built images from public repositories or to push and distribute their own images. Docker Hub simplifies the process of finding and using images created by others, fostering collaboration within the developer community.
## Conclusion
Docker revolutionizes the way applications are developed, shipped, and deployed by providing a consistent environment that works across various platforms. Through the use of containers, Docker makes applications portable, scalable, and easy to manage. Its comprehensive ecosystem of tools and services has established Docker as a critical component in modern software development pipelines, enabling faster, more reliable deployment of applications.

View File

@@ -0,0 +1,285 @@
# **Docker Commands Guide**
## **1. Docker Data Directories**
Docker stores essential data, including images, containers, and volumes, in specific directories.
- **`/var/lib/docker/`**: Main directory for Docker's data, including images, containers, and volumes.
- **`/var/lib/docker/containers/`**: Stores configuration files for individual containers.
- **`/var/lib/docker/volumes/`**: Stores data for Docker volumes, which persist beyond the containers lifecycle.
---
## **2. Installing Docker on Ubuntu**
### **Step 1: Update Package List and Install Dependencies**
```bash
sudo apt update && sudo apt install -y ca-certificates curl
```
- **`sudo apt update`**: Refreshes the package list.
- **`sudo apt install -y ca-certificates curl`**: Installs certificates and `curl` to securely download Docker packages.
### **Step 2: Add Dockers GPG Key**
```bash
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
```
- **`install -m 0755 -d /etc/apt/keyrings`**: Creates the `/etc/apt/keyrings` directory with appropriate permissions.
- **`curl -fsSL <url> -o <file>`**: Downloads Dockers GPG key.
- **`chmod a+r`**: Grants read permissions for all users to the GPG key.
### **Step 3: Add Dockers Official Repository**
```bash
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```
- Adds Dockers repository to the Apt sources list.
### **Step 4: Install Docker**
```bash
sudo apt update && sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```
- **`docker-ce`**: Installs Docker Community Edition.
- **`docker-ce-cli`**: Docker command-line interface.
- **`containerd.io`**: Container runtime.
- **`docker-buildx-plugin`**: Provides advanced build functionality.
- **`docker-compose-plugin`**: Manages multi-container applications.
---
## **3. Docker CLI Commands**
### **3.1 Authentication**
```bash
docker login
```
- **`docker login`**: Logs into Docker Hub or a private registry by prompting for credentials.
### **3.2 Image Management**
- **Download an image:**
```bash
docker pull <repo-addr>
```
- Downloads an image from a repository.
- **List images:**
```bash
docker images
```
- Displays all available images.
- **Remove an image:**
```bash
docker rmi -f <image-id>
```
- Forcefully removes a specific image.
- **Save an image as a `.tar` file:**
```bash
docker save -o <file-location-and-name> <image-name>
```
- **Load an image from a `.tar` file:**
```bash
docker load -i <file-location>
```
### **3.3 Container Management**
- **Run a container:**
```bash
docker run <options> <image-name>
```
- **Run an interactive container with a terminal:**
```bash
docker run -it <image-name>
```
- **Run a container in detached mode:**
```bash
docker run -dit <image-name>
```
- **Set a container to always restart:**
```bash
docker run -dit --restart=always <image-name>
```
- **Name a container:**
```bash
docker run -dit --name <container-name> <image-name>
```
- **Assign a hostname:**
```bash
docker run -dit --hostname=<hostname> <image-name>
```
- **Set environment variables:**
```bash
docker run -dit -e var1=data --name <container-name> --hostname=<hostname> <image-name>
```
- **Map host and container ports:**
```bash
docker run -dit -p <host-port>:<container-port> <image-name>
```
- **Run a container with memory and CPU limits:**
```bash
docker run -dit --name nginx --memory-reservation 150m --memory 500m nginx
```
- Limits memory reservation to 150MB and usage to a maximum of 500MB.
```bash
docker run -dit --name nginx --cpus 2 --cpu-shares 100 nginx
```
- Limits the container to 2 CPUs.
- **Stream container logs in real-time:**
```bash
docker logs -f <container-name>
```
- **Access a containers terminal:**
```bash
docker exec -it <container-name> /bin/bash
```
- **Stop a container:**
```bash
docker stop <container-name>
```
- **Remove a container:**
```bash
docker rm <container-name>
```
- **Forcefully remove a running container:**
```bash
docker rm -f <container-name>
```
- **List all container IDs (including stopped):**
```bash
docker ps -aq
```
- **Prune stopped containers:**
```bash
docker container prune
```
- **Commit a container to an image:**
```bash
docker commit <container-name> <new-image-name>
```
- **Inspect container details:**
```bash
docker inspect <container-name>
```
- **Copy files between host and container:**
```bash
docker cp <file-on-local> <container-name>:/<container-path>
```
```bash
docker cp <container-name>:/<container-path> <local-path>
```
- **View real-time container resource usage:**
```bash
docker stats
```
- **Build an image from a Dockerfile:**
```bash
docker build -t <app-name>:<app-version> <path-to-dockerfile>
```
---
## **4. Volume Management**
Volumes store data that persists even when a container is deleted.
- **List all volumes:**
```bash
docker volume ls
```
- **Create a volume:**
```bash
docker volume create <volume-name>
```
- **Inspect a volume:**
```bash
docker volume inspect <volume-name>
```
- **Mount a volume to a container:**
```bash
docker run -dit --name <container-name> -v <volume-name>:<container-path> <image-name>
```
- **Mount a file with read-only access:**
```bash
docker run -dit --name nginx -v /etc/resolv.conf:/etc/resolv.conf:ro nginx
```
- **Mount temporary filesystem in memory:**
```bash
docker run -dit --name nginx --tmpfs /opt:100M nginx
```
---
## **5. Network Management**
Docker networks allow communication between containers.
- **List all networks:**
```bash
docker network ls
```
- **Create a network:**
```bash
docker network create <network-name>
```
- **Create a custom network with subnet and gateway:**
```bash
docker network create --subnet <subnet> --gateway <gateway-ip> --driver=<network-type> <network-name>
```
- **Run a container on a specific network:**
```bash
docker run -dit --name <container-name> --network <network-name> <image-name>
```
- **Connect a running container to a network:**
```bash
docker network connect <network-name> <container-name>
```
- **Disconnect a container from a network:**
```bash
docker network disconnect <network-name> <container-name>
```
---
## **6. System Commands**
- **Show Docker Disk usage:**
```bash
docker system df
```
- **Remove Unuse Cache,Container And More**
- ```bash
- docker system prune
- ```
-
-

View File

@@ -0,0 +1,160 @@
# 🚢 Understanding Dockerfile: A Complete Guide
---
## 📄 What is a Dockerfile?
A **Dockerfile** is a simple text file containing instructions to create a **Docker image**. Docker images provide a consistent, reproducible environment to run applications inside containers. By defining dependencies, configurations, and the operating system, Dockerfiles automate image creation, ensuring version-controlled and portable environments.
---
### 🔑 Key Concepts:
* 🏗️ **Base Image**: The foundational layer of your image, usually an official OS like Ubuntu, CentOS, or Alpine Linux.
* 📝 **Instructions**: Commands that tell Docker what to install, how the image behaves, and which files to include.
Common instructions include:
| Instruction | Description |
| ----------- | ---------------------------------------------------------------- |
| 🏃‍♂️ `RUN` | Executes commands inside the container (e.g., install software). |
| 📁 `COPY` | Copies files from your local machine to the image. |
| ▶️ `CMD` | Specifies the default command when the container starts. |
---
## 🛠️ Step-by-Step Guide to Creating a Dockerfile
---
### 1⃣ Create a File Named `Dockerfile`
Create a file called `Dockerfile` in your project directory. If named differently, specify the filename during build.
#### Example Dockerfile:
```dockerfile
# 🐧 Use Ubuntu 22.04 as the base image
FROM ubuntu:22.04
# 🏷️ Add metadata such as version information
LABEL version="0.0.1"
# 🔄 Update package lists and install essential tools
RUN apt update && apt install -y bash vim curl
# 🌐 Install Nginx web server
RUN apt install -y nginx
```
**Explanation:**
* `FROM ubuntu:22.04` — Use Ubuntu 22.04 as the base image.
* `LABEL version="0.0.1"` — Adds version metadata.
* `RUN` — Executes commands inside the container to install tools and software.
---
### 2⃣ Example Using Alpine Linux
Alpine Linux is lightweight and creates smaller images.
```dockerfile
# 🐧 Use Alpine as the base image
FROM alpine
# 🏷️ Add version metadata
LABEL version="0.0.1"
# 🔄 Update package lists and install essential tools
RUN apk update && apk add bash vim curl
```
Perfect for a compact, minimalistic image.
---
### 3⃣ Complex Dockerfile with a Script
```dockerfile
# 🐧 Start with Alpine as the base image
FROM alpine
# 🏷️ Add metadata
LABEL version="0.0.1"
# 🔄 Update packages and install essential tools
RUN apk update && apk add bash vim curl iputils-ping
# 📂 Copy the script into the image
COPY <local-file-path> <container-destination-path>
# 🏠 Set working directory
WORKDIR <container-destination-path>
# 🌿 Add environment variables
ENV API_KEY="123445"
# 👤 Set user and expose ports
USER deploy
EXPOSE 3210
# ⚙️ Make the script executable
RUN chmod +x app.sh
# ▶️ Default command to run
CMD ["./app.sh"]
# Alternatively, ENTRYPOINT ensures always running the executable
ENTRYPOINT ["bash", "./app.sh"]
```
---
### ❤️ Health Check Setup
```dockerfile
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
CMD curl -f http://localhost/ || exit 1
```
* ⏲️ **interval**: time between checks
***timeout**: fail if check takes longer than 5 seconds
* 🔄 **retries**: mark container unhealthy after failed attempts
* 🛡️ **start-period**: grace period before counting failures
---
### 4⃣ Build Your Docker Image
```bash
docker build -t <app-name> <path-to-dockerfile>
```
**Examples:**
* Build with Dockerfile in current directory:
```bash
docker build -t app-test .
```
* Use custom Dockerfile name:
```bash
docker build -t app-test -f <CustomDockerfile> .
```
* Build without cache:
```bash
docker build -t app-test:v1 -f <Custom-Dir> . --no-cache
```
---
## 📋 Summary
A **Dockerfile** is a powerful tool for automating Docker image creation:
1. 📝 **Create a Dockerfile**: Define the image with `FROM`, `RUN`, `COPY`, and `CMD`.
2. 🏗️ **Build the Image**: Use `docker build` to generate your image.
3. 🚀 **Run the Container**: Use `docker run` to start your container.

View File

@@ -0,0 +1,83 @@
# **Docker Compose Guide**
Docker Compose is a tool for defining and running multi-container Docker applications. It allows you to manage services, networks, and volumes using a YAML configuration file.
---
## **1. Basic Docker Compose Structure**
Before defining the services in Docker Compose, we need to specify the Docker Compose version and the services we want to run. Here's a basic YAML template:
```yaml
version: "<python-version>"
services:
<service-name>: # The name of your service (e.g., web, db)
container_name: <container-name> # The name of the container
image: <image-name> # Docker image to be used for this service
restart: always # Ensure the container restarts if it stops or fails
ports:
- "<sv-port>:<container-port>" # Map the host port to the container port
volumes:
- <vol-name>:<container-loc> # Attach a volume to a specific location in the container
environment:
- <env1>=<value1> # Environment variables to be passed to the container
```
### **Explanation**:
- **`services:`**: The core section where you define different services (containers) that make up your application.
- **`<service-name>`**: Replace with the name of the service (e.g., `web`, `database`). Each service corresponds to a container.
- **`container_name`**: The name given to the container.
- **`image`**: The Docker image used to run the service (e.g., `python:3.9`, `nginx`).
- **`restart: always`**: Ensures the container will always restart if it stops, providing higher availability.
- **`ports`**: Maps ports from the host to the container, allowing the container to be accessed externally. The syntax is `<host-port>:<container-port>`.
- **`volumes`**: Links a Docker volume or host directory to a directory inside the container, enabling persistent data or sharing of resources. Example: `myvolume:/usr/src/app`.
- **`environment`**: Defines environment variables to be passed to the container at runtime. For example, setting an environment variable like `DB_HOST=localhost`.
---
## **2. Defining Volumes**
Docker Compose allows you to define persistent volumes that can be attached to containers. Here's how to define a volume:
```yaml
volumes:
<vol-name>: # Define the volume here
```
### **Explanation**:
- **`volumes:`**: This section allows you to define named volumes that can be used in the services.
- **`<vol-name>`**: Replace this with the name of the volume (e.g., `data-volume`, `db-volume`). The volume can be attached to different services to persist data beyond the container's lifecycle.
---
## **3. Useful Docker Compose Commands**
### **3.1 Start the Docker Compose Application**
To bring up the application defined in the `docker-compose.yml` file, use:
```bash
docker compose up
```
### **3.2 Run Docker Compose in Detached Mode (Background)**
To run your Docker Compose services in the background (detached mode):
```bash
docker compose up -d
```
### **3.3 Stop and Remove Docker Compose Services**
To stop the services and remove the containers, networks, and volumes created by Docker Compose:
```bash
docker compose down
```
### **Explanation of Commands**:
- **`docker compose up`**: Builds, (re)creates, and starts all services defined in the `docker-compose.yml` file.
- **`docker compose up -d`**: Runs the services in the background, keeping your terminal free while the containers continue running.
- **`docker compose down`**: Stops and removes all running services, containers, and networks created by Docker Compose. You can add the `-v` flag to remove volumes as well.

View File

@@ -0,0 +1,228 @@
# 📦 Docker Swarm Documentation
Comprehensive guide to managing a **Docker Swarm** cluster. This document includes core commands, workflows, and best practices for maintaining a healthy and operational environment.
---
## 📚 Table of Contents
1. [🔧 Cluster Health & Manager Count](#-cluster-health--manager-count)
2. [🚀 Example Workflow: Setting Up Nginx](#-example-workflow-setting-up-nginx)
3. [⚙️ Cluster Initialization and Management](#-cluster-initialization-and-management)
4. [🖥️ Node Management](#-node-management)
5. [🛠️ Service Management](#-service-management)
6. [🔑 Join Tokens & Node Configuration](#-join-tokens--node-configuration)
---
## 🔧 Cluster Health & Manager Count
A Docker Swarm cluster requires a **majority of manager nodes** to be functional for quorum.
> **Best Practice:** Always maintain **more than 50%** manager nodes online. Losing quorum will render the cluster non-operational.
---
## 🚀 Example Workflow: Setting Up Nginx
Docker Swarm handles service deployment through several internal components:
1. **API** Receives service requests.
2. **Allocator** Determines resource allocation.
3. **Dispatcher** Assigns tasks to nodes.
4. **Scheduler** Places tasks on optimal nodes.
This process ensures resilient and efficient service distribution.
---
## ⚙️ Cluster Initialization and Management
### 🔹 Initialize Cluster
```bash
docker swarm init
```
### 🔹 Initialize with Specific Interface
```bash
docker swarm init --advertise-addr <ip-or-interface>
```
### 🔹 Join Existing Cluster
```bash
docker swarm join
```
### 🔹 Leave Cluster
```bash
docker swarm leave
```
### 🔹 Unlock a Manager Node
```bash
docker swarm unlock
```
---
## 🖥️ Node Management
### 🔸 List Nodes
```bash
docker node ls
```
**Example Output:**
```
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
8yw8jrjeqczaci0qkuy060g09 * docker-1 Ready Active Leader 24.0.5
v4gvf7xenw0izmxgvhr6hb2rj docker-2 Ready Active 24.0.5
kd3ujmt1ey3pw6v9189fouxfa docker-3 Ready Active Reachable 24.0.5
tm1msy58ztcltt36rs1lb76p7 docker-4 Down Active 24.0.5
```
### 🔸 Remove a Node
```bash
docker node rm <node-id>
```
### 🔸 Promote to Manager
```bash
docker node promote <hostname-or-id>
```
### 🔸 Inspect a Node
```bash
docker node inspect <nodename>
```
### 🔸 Change Node Role
```bash
docker node update --role manager <nodename>
docker node update --role worker <nodename>
```
### 🔸 Change Node Availability
```bash
docker node update --availability active <nodename>
docker node update --availability pause <nodename>
docker node update --availability drain <nodename>
```
### 🔸 Add or Remove Labels
**Add:**
```bash
docker node update --label-add env=development <nodename>
docker node update --label-add env=testing <nodename>
```
**Remove:**
```bash
docker node update --label-rm env= <nodename>
docker node update --label-rm env <nodename>
```
**Use label constraints in service deployment:**
```yaml
deploy:
placement:
constraints:
- node.labels.env == development
```
---
## 🛠️ Service Management
### 🔹 Show Tasks on a Node
```bash
docker node ps
```
### 🔹 List All Services
```bash
docker service ls
```
### 🔹 Create a New Service
```bash
docker service create --name <service-name> <image-name>
```
### 🔹 Scale a Service
```bash
docker service scale <service-name>=<replica-count>
```
**Example:**
```bash
docker service scale nginx=5
```
### 🔹 Inspect a Service
```bash
docker service inspect <service-name>
```
### 🔹 Create Service with Replicas, Env Vars, and Port Mapping
```bash
docker service create \
--name <service-name> \
--replicas <count> \
--env <ENV_VAR=value> \
--publish <host-port>:<container-port> \
<image-name>
```
**Example:**
```bash
docker service create \
--name nginx \
--replicas 3 \
--env MY_ENV_VAR=value \
--publish 8080:80 \
nginx
```
---
## 🔑 Join Tokens & Node Configuration
Securely add nodes to your Swarm using join tokens.
### 🔹 Get Worker Token
```bash
docker swarm join-token worker
```
### 🔹 Get Manager Token
```bash
docker swarm join-token manager
```

View File

@@ -0,0 +1,102 @@
# HTTP Status Codes Table
| Status Code | Category | Description |
|-------------|------------------------|---------------------------------------------------------------------------------------|
| **100** | Informational (1xx) | Continue: The client should continue with its request. |
| **101** | Informational (1xx) | Switching Protocols: Server is switching protocols. |
| **102** | Informational (1xx) | Processing (WebDAV): Server has received and is processing the request. |
| **200** | Success (2xx) | OK: The request was successful. |
| **201** | Success (2xx) | Created: The request was successful and a resource was created. |
| **202** | Success (2xx) | Accepted: The request has been accepted for processing. |
| **203** | Success (2xx) | Non-Authoritative Information: The server is a proxy, not the original. |
| **204** | Success (2xx) | No Content: The server successfully processed the request, but no content is returned.|
| **205** | Success (2xx) | Reset Content: The client should reset the view. |
| **206** | Success (2xx) | Partial Content: The server is delivering part of the resource (range requests). |
| **300** | Redirection (3xx) | Multiple Choices: Multiple options for the resource are available. |
| **301** | Redirection (3xx) | Moved Permanently: The resource has moved permanently to a new URI. |
| **302** | Redirection (3xx) | Found: The resource is temporarily at a different URI. |
| **303** | Redirection (3xx) | See Other: The response is at another URI. |
| **304** | Redirection (3xx) | Not Modified: The resource has not been modified since the last request. |
| **305** | Redirection (3xx) | Use Proxy: The requested resource is available only through a proxy. |
| **307** | Redirection (3xx) | Temporary Redirect: The resource resides temporarily at a different URI. |
| **308** | Redirection (3xx) | Permanent Redirect: The resource has moved permanently, and this URI should be used. |
| **400** | Client Errors (4xx) | Bad Request: The server could not understand the request due to invalid syntax. |
| **401** | Client Errors (4xx) | Unauthorized: Authentication is required and has failed. |
| **402** | Client Errors (4xx) | Payment Required: Reserved for future use. |
| **403** | Client Errors (4xx) | Forbidden: The request was understood but refuses to authorize it. |
| **404** | Client Errors (4xx) | Not Found: The resource could not be found. |
| **405** | Client Errors (4xx) | Method Not Allowed: The request method is not supported for the resource. |
| **406** | Client Errors (4xx) | Not Acceptable: The resource cannot produce content acceptable to the client. |
| **407** | Client Errors (4xx) | Proxy Authentication Required: The client must authenticate with the proxy first. |
| **408** | Client Errors (4xx) | Request Timeout: The server timed out waiting for the request. |
| **409** | Client Errors (4xx) | Conflict: The request could not be processed because of a conflict. |
| **410** | Client Errors (4xx) | Gone: The resource is no longer available. |
| **411** | Client Errors (4xx) | Length Required: The request did not specify the length. |
| **412** | Client Errors (4xx) | Precondition Failed: The preconditions set by the client were not met. |
| **413** | Client Errors (4xx) | Payload Too Large: The request is too large to process. |
| **414** | Client Errors (4xx) | URI Too Long: The URI provided was too long for the server to process. |
| **415** | Client Errors (4xx) | Unsupported Media Type: The media type of the request is not supported. |
| **416** | Client Errors (4xx) | Range Not Satisfiable: The client requested a portion that cannot be supplied. |
| **417** | Client Errors (4xx) | Expectation Failed: The server cannot meet the expectation of the request. |
| **418** | Client Errors (4xx) | I'm a teapot (RFC 2324): An April Fools' joke code. |
| **421** | Client Errors (4xx) | Misdirected Request: The request was directed at a wrong server. |
| **422** | Client Errors (4xx) | Unprocessable Entity (WebDAV): The request was well-formed but semantic errors exist. |
| **423** | Client Errors (4xx) | Locked (WebDAV): The resource being accessed is locked. |
| **424** | Client Errors (4xx) | Failed Dependency (WebDAV): A previous request failed, causing this one to fail. |
| **425** | Client Errors (4xx) | Too Early: The server is unwilling to process this request yet. |
| **426** | Client Errors (4xx) | Upgrade Required: The client needs to switch to a different protocol. |
| **428** | Client Errors (4xx) | Precondition Required: The server requires the request to be conditional. |
| **429** | Client Errors (4xx) | Too Many Requests: Too many requests sent in a given amount of time. |
| **431** | Client Errors (4xx) | Request Header Fields Too Large: The request's header fields are too large. |
| **451** | Client Errors (4xx) | Unavailable For Legal Reasons: The resource is unavailable for legal reasons. |
| **500** | Server Errors (5xx) | Internal Server Error: An unexpected server error occurred. |
| **501** | Server Errors (5xx) | Not Implemented: The server lacks the ability to fulfill the request. |
| **502** | Server Errors (5xx) | Bad Gateway: Received an invalid response from the upstream server. |
| **503** | Server Errors (5xx) | Service Unavailable: The server is overloaded or down for maintenance. |
| **504** | Server Errors (5xx) | Gateway Timeout: No timely response from the upstream server. |
| **505** | Server Errors (5xx) | HTTP Version Not Supported: The server does not support the HTTP version. |
| **506** | Server Errors (5xx) | Variant Also Negotiates: Internal configuration error. |
| **507** | Server Errors (5xx) | Insufficient Storage (WebDAV): The server cannot store the representation. |
| **508** | Server Errors (5xx) | Loop Detected (WebDAV): The server detected an infinite loop while processing. |
| **510** | Server Errors (5xx) | Not Extended: Extensions are required for the server to fulfill the request. |
| **511** | Server Errors (5xx) | Network Authentication Required: Client must authenticate to gain network access. |
---
# Docker Image Layers
A **Docker image** is composed of multiple layers that work together to create a fully functional container. Each layer represents a step in the build process, and layers are stacked on top of one another to form the complete image.
### Structure of a Docker Image:
1. **BootFS (Boot File System):**
- **Description:** This is the bottom-most layer in the Docker image. It includes files and directories needed to boot up a system.
- **Function:** It sets up the foundation for the base operating system within the container, similar to the host machines `/boot` folder.
2. **Base Image:**
- **Description:** The base image is typically a minimal operating system (e.g., Ubuntu, Alpine Linux) or any other image that acts as a starting point for your container.
- **Examples:** Ubuntu, Alpine, Debian.
- **Function:** Provides the core OS functionalities and dependencies needed for the higher layers.
3. **Libraries:**
- **Description:** Libraries required by the applications running in the container.
- **Examples:** libc, libssl, or any other standard libraries needed by the applications.
- **Function:** Provides necessary functionality for applications, ensuring they can function correctly within the container.
4. **Packages and Applications:**
- **Description:** Specific software, tools, or libraries that your application depends on.
- **Examples:** vim, curl, git, node.js, or custom software required by your application.
- **Function:** These packages allow you to run applications and scripts necessary for the container's purpose.
5. **User Application (Optional):**
- **Description:** The main application code that you intend to run within the container.
- **Examples:** A web server like Apache, Nginx, or any microservice application.
- **Function:** It is the purpose of the container, which could be serving web traffic, processing data, or any other specific task.
### Writable Layer (Container-Specific):
- **Description:** Once a container is created from a Docker image, a writable layer is added on top of the image layers.
- **Function:** Any changes made during the container's runtime (like creating files or modifying configurations) are stored in this writable layer.
- **Key Point:** Changes to the writable layer do not impact the underlying image layers.
---

View File

@@ -0,0 +1,81 @@
# Docker Directory Structure in `/var/lib/docker`
In Linux, Docker stores its container data under `/var/lib/docker`. Each subdirectory here serves a specific purpose related to Docker's functionality. Below is a breakdown of each important directory under `/var/lib/docker`.
## 1. **/var/lib/docker/containers**
This directory contains the data for each Docker container. Each container has its own subdirectory, named after the container's unique ID. Inside each containers directory, youll find files like:
- `config.v2.json`: Configuration data for the container.
- `hostconfig.json`: Configuration related to how the container was launched.
- `log.json`: The logs generated by the container.
**Example:**
```bash
/var/lib/docker/containers/[container_id]/config.v2.json
```
## 2. **/var/lib/docker/image**
This directory contains Docker images. Images are stored in subdirectories based on their storage driver (e.g., `overlay2`, `aufs`, etc.).
**Key subdirectories:**
- `/var/lib/docker/image/overlay2/`: Stores metadata and layers for images using the `overlay2` storage driver.
## 3. **/var/lib/docker/overlay2**
The `overlay2` directory contains the layers of the Docker images and containers. Each image and container is made up of multiple layers, which are stored in this directory. The overlay filesystem merges these layers to create a unified view of the container's filesystem.
**Key subdirectories:**
- `diff/`: Stores the content changes for each layer.
- `merged/`: Represents the merged view of the layers for running containers.
- `work/`: Temporary working directories for file operations.
## 4. **/var/lib/docker/plugins**
This directory is where Docker stores data related to plugins. Docker plugins extend the platform's capabilities by adding features such as storage drivers, networking plugins, and logging mechanisms.
**Subdirectory structure:**
- `/var/lib/docker/plugins/[plugin_id]/`: Each installed plugin has its own subdirectory.
## 5. **/var/lib/docker/network**
This directory stores data related to Docker's networking functionality. Docker allows containers to communicate with each other through networks, and this directory holds information about those networks.
**Key subdirectories:**
- `files/`: Contains JSON files that describe the networks.
- `local-kv.db`: A database that stores network state information.
## 6. **/var/lib/docker/swarm**
This directory holds data related to Docker Swarm mode, which allows you to deploy and manage a cluster of Docker nodes. The swarm directory is used for storing cluster state, such as node configurations and services.
**Key files:**
- `worker/`: Contains information specific to the worker nodes in a swarm.
- `raft/`: Contains data for the Raft consensus algorithm used to manage the swarm cluster state.
## 7. **/var/lib/docker/volumes**
This directory contains data for Docker volumes, which are used for persisting data outside of the container lifecycle. Each volume is stored in its own subdirectory.
**Example:**
```bash
/var/lib/docker/volumes/[volume_name]/_data/
```
The `_data` subdirectory inside each volume contains the actual persistent data for that volume.
## 8. **/var/lib/docker/builder**
This directory stores information related to the Docker image build process. It includes cache data and temporary files generated while building Docker images.
**Key files:**
- `cache/`: Contains cached layers used during the image building process to speed up future builds.
## 9. **/var/lib/docker/runtimes**
This directory contains data related to different container runtimes. While Docker primarily uses `runc`, other runtimes like `nvidia` can also be installed here.
## 10. **/var/lib/docker/tmp**
Temporary files used by Docker are stored in this directory. These are usually short-lived and can include things like temporary layers during builds or container creation processes.

View File

@@ -0,0 +1,74 @@
version: "3.8"
services:
web:
image: nginx:alpine
ports:
- "80:80"
deploy:
# Service mode: use "replicated" for a set number of replicas,
# or "global" to run one instance on every node.
mode: replicated
# Number of container replicas to run (only applicable in replicated mode)
replicas: 3
# Rolling update configuration (applies when updating the service)
update_config:
# Number of containers to update at the same time
parallelism: 2
# Delay between updating groups of containers (e.g., "10s" for 10 seconds)
delay: 10s
# Action to take if an update fails: rollback, pause, or continue
failure_action: rollback
# Time to monitor each updated container before proceeding to the next batch
monitor: 10s
# Maximum failure ratio (0.0 to 1.0) acceptable during the update
max_failure_ratio: 0.3
# Rollback configuration (applies if a deployment needs to be undone)
rollback_config:
parallelism: 1
delay: 10s
# Action to take if rollback fails
failure_action: pause
monitor: 10s
max_failure_ratio: 0.2
# Restart policy for containers in the service
restart_policy:
# Restart condition can be "none", "on-failure", or "any"
condition: on-failure
# Delay between restart attempts
delay: 5s
# Maximum number of restart attempts before considering the container as failed
max_attempts: 3
# Time window used to evaluate restart attempts (e.g., "120s")
window: 120s
# Resource constraints and reservations for containers
resources:
limits:
# Maximum number of CPUs the container can use (as a fraction or whole number)
cpus: "0.50"
# Maximum memory (e.g., "50M" for 50 megabytes)
memory: 50M
reservations:
# Guaranteed minimum CPUs for the container
cpus: "0.25"
# Guaranteed minimum memory
memory: 20M
# Placement constraints and preferences to control which nodes run the service
placement:
# Constraints ensure that only nodes meeting certain conditions are eligible.
constraints:
- node.role == manager
- node.labels.region == us-east
# Preferences allow you to influence (but not enforce) distribution.
preferences:
- spread: node.labels.az
# Custom metadata labels for the service
labels:
com.example.description: "Sample web service using all deploy parameters"