### Install Docker using Convenience Script Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Use this script for a quick Docker setup on Linux. It automatically detects your distribution and installs Docker. ```bash wget -qO- https://get.docker.com | sh ``` -------------------------------- ### Start and Enable Docker Service Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md After installation, start the Docker service and enable it to launch on system boot. ```bash sudo systemctl start docker ``` ```bash sudo systemctl enable docker ``` -------------------------------- ### Install Docker on Linux using convenience script Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt This script automatically detects your Linux distribution and installs Docker Engine. It also includes commands to start and enable the Docker daemon and add your user to the docker group for non-sudo access. Verify the installation with `docker version` and `docker run hello-world`. ```bash # Download and run the official install script wget -qO- https://get.docker.com | sh # Start and enable the daemon sudo systemctl start docker sudo systemctl enable docker # Allow the current user to run docker without sudo (re-login required) sudo usermod -aG docker $USER # Verify the installation docker version docker run hello-world # Expected output: "Hello from Docker!" message confirming daemon is reachable ``` -------------------------------- ### Manual Docker installation on Ubuntu Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Provides step-by-step instructions for manually installing Docker CE on Ubuntu, including updating package lists, installing necessary prerequisites, adding the Docker repository, and installing the Docker packages. Confirms the daemon status. ```bash sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli containerd.io # Confirm daemon is running sudo systemctl status docker ``` -------------------------------- ### Dockerfile for Nginx Image Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/004-docker-images.md Example Dockerfile to build a custom Nginx image. It starts from an Ubuntu base, installs Nginx, copies a custom configuration, exposes port 80, and sets the default command to run Nginx. ```dockerfile FROM ubuntu:20.04 RUN apt-get update && apt-get install -y nginx COPY ./my-nginx.conf /etc/nginx/nginx.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"] ``` -------------------------------- ### Per-Service Dockerfile Example Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt A basic Dockerfile for a Node.js application, defining the base image, working directory, dependency installation, code copying, port exposure, and the command to run the application. ```dockerfile # Per-service Dockerfile FROM node:14-alpine WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000 CMD ["node", "server.js"] ``` -------------------------------- ### Dockerfile for Caching Example Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/004-docker-images.md Illustrates Dockerfile best practices for leveraging build cache. Instructions that change less frequently (like installing dependencies) are placed before those that change often (like copying source code). ```dockerfile FROM ubuntu:20.04 RUN apt-get update && apt-get install -y nginx COPY ./static-files /var/www/html COPY ./config-files /etc/nginx ``` -------------------------------- ### Install Prerequisites on Ubuntu Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Install necessary packages for Docker installation on Ubuntu, including transport HTTPS and certificate management tools. ```bash sudo apt-get install apt-transport-https ca-certificates curl software-properties-common ``` -------------------------------- ### Add Helm Repository and Install WordPress Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/010-docker-and-kubernetes.md Add the Bitnami Helm repository and install WordPress using Helm, simplifying the deployment of complex applications. ```bash helm repo add bitnami https://charts.bitnami.com/bitnami ``` ```bash helm install my-release bitnami/wordpress ``` -------------------------------- ### Verify Docker Installation Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Run these commands to verify that Docker is installed correctly and that the 'hello-world' container runs as expected. ```bash docker version ``` ```bash docker run hello-world ``` -------------------------------- ### Start Minikube and enable dashboard Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Commands to start a local Kubernetes cluster with Minikube and enable the dashboard for cluster visualization. ```bash minikube start minikube addons enable dashboard minikube dashboard ``` -------------------------------- ### Install Docker CE on Ubuntu Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Install Docker Engine, CLI, and Containerd on Ubuntu after setting up the repository. ```bash sudo apt-get install docker-ce docker-ce-cli containerd.io ``` -------------------------------- ### Enable Docker to Start on Boot (Linux) Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Use this command on Linux systems to configure Docker to start automatically when the system boots up. ```bash sudo systemctl enable docker ``` -------------------------------- ### Create a Volume Using a Plugin Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/007-docker-volumes.md Installs a third-party volume plugin and then creates a volume using that plugin for extended functionality. ```bash docker plugin install docker volume create -d my_volume ``` -------------------------------- ### Multi-stage Build Example Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/005-dockerfile.md Demonstrates a multi-stage build to create smaller final images by separating build-time dependencies from runtime dependencies. ```dockerfile FROM node:14 AS build WORKDIR /app COPY package*.json ./ RUN npm install COPY . . RUN npm run build FROM nginx:alpine COPY --from=build /app/dist /usr/share/nginx/html ``` -------------------------------- ### Start Minikube Cluster Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/010-docker-and-kubernetes.md Use this command to start a local Kubernetes cluster with Minikube for testing and development purposes. ```bash minikube start ``` -------------------------------- ### Start Docker Service (Linux) Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md If the Docker daemon is not running on a Linux system, use this command to start the service. ```bash sudo systemctl start docker ``` -------------------------------- ### Install Prometheus and Grafana with Helm Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/010-docker-and-kubernetes.md Use Helm to install Prometheus for monitoring and Grafana for visualization in your Kubernetes cluster. ```bash helm install prometheus stable/prometheus ``` ```bash helm install grafana stable/grafana ``` -------------------------------- ### Run a Hello World Container Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/003-docker-containers.md Executes the 'hello-world' image to verify Docker installation and basic functionality. It pulls the image if not found locally, creates, and runs the container. ```bash docker run hello-world ``` -------------------------------- ### Install and Use Docker SSHFS Plugin Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/013-docker-tips.md Extend Docker functionality by installing a plugin, such as vieux/sshfs, and then using it to create a volume. ```bash # Install a plugin docker plugin install vieux/sshfs ``` ```bash # Use the plugin docker volume create -d vieux/sshfs -o sshcmd=user@host:/path sshvolume ``` -------------------------------- ### Practical Example: Running and Modifying Apache Container Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/003-docker-containers.md Demonstrates pulling an Apache image, running it with port mapping and a name, and then executing a command inside the container to modify its default index page. ```bash docker pull httpd ``` ```bash docker run -d --name my-apache -p 8080:80 httpd ``` ```bash docker ps ``` ```bash docker exec -it my-apache /bin/bash echo "

Hello from my Apache container!

" > /usr/local/apache2/htdocs/index.html exit ``` -------------------------------- ### Docker Compose Setup and Test in Travis CI Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/014-docker-ci-cd.md This Travis CI configuration uses Docker Compose to set up a multi-container environment, install dependencies, run tests, and clean up. ```yaml # Travis CI example services: - docker before_install: - docker-compose up -d - docker-compose exec -T app npm install script: - docker-compose exec -T app npm test after_success: - docker-compose down ``` -------------------------------- ### Install Docker CE on CentOS Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Install Docker Engine and CLI on CentOS after configuring the Docker repository. ```bash sudo yum install docker-ce docker-ce-cli containerd.io ``` -------------------------------- ### Docker Compose Profiles for Selective Service Startup Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/013-docker-tips.md Use profiles in Docker Compose to selectively start services. Define profiles for services and then use the --profile flag to start specific ones. ```yaml services: frontend: image: frontend profiles: ["frontend"] backend: image: backend profiles: ["backend"] ``` ```bash docker-compose --profile frontend up -d ``` -------------------------------- ### Update Package Index on Ubuntu Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Before installing Docker on Ubuntu, update your system's package index to ensure you get the latest versions. ```bash sudo apt-get update ``` -------------------------------- ### Sample Microservice Dockerfile Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/015-docker-microservices.md A basic Dockerfile for a Node.js microservice. It installs dependencies, copies application code, and exposes the application port. ```dockerfile FROM node:14-alpine WORKDIR /usr/src/app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000 CMD ["node", "server.js"] ``` -------------------------------- ### Get Docker Swarm Information Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/099-docker-swarm.md Displays detailed information about the Docker installation and the Swarm cluster's current state. This includes swarm status, node count, and other configuration details. ```bash docker info ``` -------------------------------- ### Update Docker CE on Ubuntu Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Example command for updating Docker CE on Ubuntu using apt-get. ```bash sudo apt-get upgrade docker-ce ``` -------------------------------- ### Set Up Docker Stable Repository on Ubuntu Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Configure the stable Docker repository for your Ubuntu distribution to ensure you install the official Docker CE. ```bash sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ``` -------------------------------- ### Set Up AutoML Environment with Docker Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/016-docker-ml.md Dockerfile to create an environment for AutoML using the auto-sklearn library. Installs the library and copies the AutoML script. ```dockerfile FROM python:3.8 RUN pip install auto-sklearn COPY automl_script.py . CMD ["python", "automl_script.py"] ``` -------------------------------- ### Start an interactive shell in a temporary container Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Starts a temporary Ubuntu container, provides an interactive bash shell, and automatically removes the container upon exit. The `--rm` flag is key for temporary containers. Useful for quick testing or exploration. ```bash # Interactive shell for a temporary container (removed on exit) docker run -it --rm ubuntu:20.04 /bin/bash ``` -------------------------------- ### Run New Container with Shell for Debugging Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Start a new container and immediately launch a shell, overriding the default entrypoint. Useful for exploring an image's filesystem or debugging startup issues. ```bash docker run -it --entrypoint /bin/bash ``` -------------------------------- ### Build Docker Image with Build Argument in CI/CD Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/014-docker-ci-cd.md Example of building a Docker image in a CI/CD pipeline, passing an environment-specific configuration file as a build argument. ```yaml build: script: - docker build --build-arg CONFIG_FILE=${ENV}.conf -t myapp:${CI_COMMIT_SHA} . ``` -------------------------------- ### Uninstall Docker CE on Ubuntu Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Example command for purging Docker CE and related packages on Ubuntu. ```bash sudo apt-get purge docker-ce docker-ce-cli containerd.io ``` -------------------------------- ### Microservice REST API Example Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/015-docker-microservices.md An Express.js example demonstrating a simple REST API endpoint for a microservice. This code listens on port 3000. ```javascript // Express.js example const express = require('express'); const app = express(); app.get('/api/data', (req, res) => { res.json({ message: 'Data from Microservice A' }); }); app.listen(3000, () => console.log('Microservice A listening on port 3000')); ``` -------------------------------- ### Install Required Packages on CentOS Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Install essential packages for Docker on CentOS, including yum-utils for repository management. ```bash sudo yum install -y yum-utils device-mapper-persistent-data lvm2 ``` -------------------------------- ### Run container with resource constraints Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Launches a container with specified memory and CPU limits. This is useful for controlling resource consumption of applications. The example limits the container to 512MB of memory and 0.5 CPU cores. ```bash # Constrain resources at launch docker run -d --memory=512m --cpus=0.5 --name limited-app nginx ``` -------------------------------- ### Dockerignore file example Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Specifies files and directories to exclude from the Docker build context, reducing build time and image size. ```dockerignore # .dockerignore — exclude files from build context .git *.md *.log node_modules ``` -------------------------------- ### Run Container in Interactive Mode Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Start a container and override its entrypoint to launch a shell. Useful for debugging containers that exit immediately. ```bash docker run -it --entrypoint /bin/sh ``` -------------------------------- ### Docker Compose for Prometheus and Grafana Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/011-docker-performance.md Example Docker Compose configuration for setting up Prometheus for monitoring and Grafana for visualization. ```yaml version: '3' services: prometheus: image: prom/prometheus volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml grafana: image: grafana/grafana ports: - "3000:3000" ``` -------------------------------- ### Define Custom Networks for Services Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/008-docker-compose.md This example shows how to define and assign custom networks ('frontend' and 'backend') to services. Services can be connected to multiple networks for better isolation and communication control. ```yaml version: '3.8' services: web: networks: - frontend - backend db: networks: - backend networks: frontend: backend: ``` -------------------------------- ### Dockerfile for Environment-Specific Configuration Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/014-docker-ci-cd.md This Dockerfile uses a build argument to specify a configuration file, allowing for environment-specific setups. ```dockerfile ARG CONFIG_FILE=default.conf COPY config/${CONFIG_FILE} /app/config.conf ``` -------------------------------- ### Set Up GPU Support for ML with NVIDIA Docker Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/016-docker-ml.md Dockerfile for an environment with GPU support using NVIDIA CUDA base image. Installs TensorFlow GPU and copies a training script. ```dockerfile FROM nvidia/cuda:11.0-base RUN pip install tensorflow-gpu COPY train.py . CMD ["python", "train.py"] ``` -------------------------------- ### Basic Docker Workflow Commands Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/001-docker.md Demonstrates the fundamental commands for building a Docker image, pushing it to a registry, and running it as a container. ```bash docker build -t myapp:v1 . ``` ```bash docker push username/myapp:v1 ``` ```bash docker run -d -p 8080:80 username/myapp:v1 ``` -------------------------------- ### Monitoring Setup with Prometheus and Grafana Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/015-docker-microservices.md A docker-compose configuration for setting up Prometheus for metrics collection and Grafana for visualization. Prometheus is configured with a local configuration file. ```yaml version: '3' services: prometheus: image: prom/prometheus volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml ports: - "9090:9090" grafana: image: grafana/grafana ports: - "3000:3000" depends_on: - prometheus ``` -------------------------------- ### Set Up Reproducible R Environment with Docker Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/016-docker-ml.md Dockerfile to create a reproducible R environment using the rocker/rstudio image. Installs R packages and runs an analysis script. ```dockerfile FROM rocker/rstudio RUN R -e "install.packages(c('ggplot2', 'dplyr'))" COPY analysis.R . CMD ["R", "-e", "source('analysis.R')"] ``` -------------------------------- ### Run Container from Docker Image Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/004-docker-images.md Execute a new container based on a specified Docker image and tag. This example runs an interactive bash session in an Ubuntu container. ```bash docker run : ``` ```bash docker run -it ubuntu:20.04 /bin/bash ``` -------------------------------- ### Docker container lifecycle commands Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Provides essential commands for managing the lifecycle of Docker containers, including stopping, starting, restarting, and removing them. Also includes commands for bulk cleanup of stopped containers and system resources. ```bash docker stop my-apache # graceful SIGTERM → SIGKILL after timeout docker start my-apache # restart a stopped container docker restart my-apache # stop + start in one command docker rm my-apache # remove a stopped container docker rm -f my-apache # force-remove a running container # Bulk cleanup docker container prune # remove all stopped containers docker system prune # remove containers, networks, dangling images docker system prune -a # also remove unused images ``` -------------------------------- ### Verificar Instalação do Docker Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/pt_br/content/002-installation.md Use este comando para confirmar se o Docker foi instalado corretamente e para visualizar informações sobre a versão e o cliente/servidor Docker. ```bash docker version ``` -------------------------------- ### Microservice Unit Testing Example Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/015-docker-microservices.md A Jest test case for a microservice API. It sends a GET request to '/api/data' and asserts that the response status code is 200 and the body contains a 'message' property. ```javascript // Jest example test('API returns correct data', async () => { const response = await request(app).get('/api/data'); expect(response.statusCode).toBe(200); expect(response.body).toHaveProperty('message'); }); ``` -------------------------------- ### Connect Container to Network (at runtime) Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/006-docker-networking.md Launches a container and connects it to a specified Docker network. The container will use the network's configuration for communication. ```bash docker run --network ``` ```bash docker run --network my_custom_network --name container1 -d nginx ``` -------------------------------- ### Check Container Entrypoint and Command Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Inspect the ENTRYPOINT and CMD defined in an image's configuration. Helps diagnose issues with containers that exit immediately. ```bash docker inspect --format='{{.Config.Entrypoint}}' ``` ```bash docker inspect --format='{{.Config.Cmd}}' ``` -------------------------------- ### Multi-stage Dockerfile for Smaller Images Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/004-docker-images.md Demonstrates a multi-stage build to create a lean production image. It uses a Go build environment to compile an application, then copies only the compiled binary into a minimal Alpine Linux image. ```dockerfile # Build stage FROM golang:1.16 AS build WORKDIR /app COPY . . RUN go build -o myapp # Production stage FROM alpine:3.14 COPY --from=build /app/myapp /usr/local/bin/myapp CMD ["myapp"] ``` -------------------------------- ### Declare Base Image with FROM Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/005-dockerfile.md Initializes a new build stage and sets the base image for subsequent instructions. This is typically the first instruction in a Dockerfile. ```dockerfile FROM ubuntu:20.04 ``` -------------------------------- ### Create and Use Custom Bridge Network Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/006-docker-networking.md Demonstrates creating a custom bridge network and launching multiple containers connected to it. Containers on the same custom bridge network can communicate using their container names as hostnames. ```bash docker network create my_bridge docker run --network my_bridge --name container1 -d nginx docker run --network my_bridge --name container2 -d nginx ``` -------------------------------- ### Configurar Docker para Usuário Não Root Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/pt_br/content/002-installation.md Adicione seu usuário ao grupo 'docker' para poder executar comandos do Docker sem `sudo`. É necessário fazer logout e login novamente para que as alterações tenham efeito. ```bash sudo usermod -aG docker ${USER} ``` -------------------------------- ### Update Docker CE on Debian/Ubuntu Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/009-docker-security.md Keep your Docker installation secure by applying the latest updates. This command fetches and installs the newest version of Docker CE. ```bash sudo apt-get update sudo apt-get upgrade docker-ce ``` -------------------------------- ### Build and Run Microservice Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/015-docker-microservices.md Commands to build a Docker image for a microservice and run it as a detached container, mapping a host port to the container port. ```bash docker build -t my-microservice . docker run -d -p 3000:3000 my-microservice ``` -------------------------------- ### Benchmark Web Server with Apache Bench Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/011-docker-performance.md Employ the Apache Bench (ab) tool to load test a web server by sending a specified number of requests. ```bash ab -n 1000 -c 100 http://localhost/ ``` -------------------------------- ### RabbitMQ Consumer Dockerfile Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/015-docker-microservices.md A Dockerfile for a Node.js microservice that uses RabbitMQ. It installs the 'amqplib' library for message queue communication. ```dockerfile # Dockerfile FROM node:14-alpine RUN npm install amqplib COPY . . CMD ["node", "consumer.js"] ``` -------------------------------- ### Create a Docker Service Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/099-docker-swarm.md Creates a new service in Docker Swarm mode. This command deploys a specified number of replicas of a given Docker image across the swarm. It maps host port 80 to the container's port 80 and names the service `bobby-web`. ```bash docker service create --name bobby-web -p 80:80 --replicas 5 bobbyiliev/php-apache ``` -------------------------------- ### Run Docker Compose in Detached Mode Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/008-docker-compose.md Starts all services defined in the docker-compose.yml file in detached mode, running them in the background. ```bash docker compose up -d ``` -------------------------------- ### Manage Docker Contexts Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/013-docker-tips.md Manage multiple Docker environments by creating, listing, and switching between contexts. ```bash # Create a new context docker context create my-remote --docker "host=ssh://user@remote-host" ``` ```bash # List contexts docker context ls ``` ```bash # Switch context docker context use my-remote ``` -------------------------------- ### Add Docker Repository on CentOS Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Add the official Docker CE repository to your CentOS system to enable installation of Docker packages. ```bash sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo ``` -------------------------------- ### Build Docker Image with Build Arguments Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Build a Docker image using Docker BuildKit and passing a build argument for environment-specific configurations. ```bash # Build with a build argument for environment-specific configs export DOCKER_BUILDKIT=1 docker build \ --build-arg CONFIG_FILE=prod.conf \ -t myapp:1.0 . ``` -------------------------------- ### Get Container IP Address Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Retrieve the IP address assigned to a container within its network. Helps in verifying network configuration. ```bash docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ``` -------------------------------- ### Build and Push Multi-Platform Images with Buildx Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/013-docker-tips.md Use the Docker Buildx plugin to build and push multi-platform images. This involves creating a builder instance and specifying platforms. ```bash # Create a new builder instance docker buildx create --name mybuilder ``` ```bash # Build and push multi-platform images docker buildx build --platform linux/amd64,linux/arm64 -t myrepo/myimage:latest --push . ``` -------------------------------- ### Kubernetes Service YAML Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/010-docker-and-kubernetes.md Define a Kubernetes Service to expose your Deployment to network traffic. This example uses a LoadBalancer type for external access. ```yaml apiVersion: v1 kind: Service metadata: name: nginx-service spec: selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80 type: LoadBalancer ``` -------------------------------- ### RUN Instruction: Shell vs. Exec Form Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/005-dockerfile.md Illustrates the two forms for the RUN instruction. The exec form is preferred for explicitness and avoiding shell-related issues. ```dockerfile RUN apt-get install python3 ``` ```dockerfile RUN ["apt-get", "install", "python3"] ``` -------------------------------- ### Inspect Container Details Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Get detailed information about a container's configuration and state. Useful for understanding why a container might not be behaving as expected. ```bash docker inspect ``` -------------------------------- ### Run Docker Container in Detached Mode Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/003-docker-containers.md Starts a container in the background, allowing you to continue using the terminal. The '-d' flag is used for detached mode. ```bash docker run -d ``` -------------------------------- ### Create and Push Docker Manifest Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/013-docker-tips.md Create and push Docker manifests to manage multi-architecture images. This involves creating a manifest list and pushing it. ```bash docker manifest create myrepo/myimage myrepo/myimage:amd64 myrepo/myimage:arm64 ``` ```bash docker manifest push myrepo/myimage ``` -------------------------------- ### Share a Volume Between Multiple Containers Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/007-docker-volumes.md Demonstrates how to mount the same volume into multiple containers, allowing them to share data. ```bash docker run -d --name container1 -v my_volume:/app nginx:latest docker run -d --name container2 -v my_volume:/app nginx:latest ``` -------------------------------- ### Build Docker Images Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Build Docker images from a Dockerfile. Options include standard build, verbose output for debugging, and building without cache. Also shows how to commit a running container to a new image. ```bash # Standard build from current directory docker build -t my-nginx:v1 . ``` ```bash # Build with verbose output (helpful for debugging cache misses) docker build --progress=plain -t my-nginx:v1 . ``` ```bash # Build ignoring all cached layers docker build --no-cache -t my-nginx:v1 . ``` ```bash # Commit a running container as a new image (quick, but prefer Dockerfiles) docker commit my-new-image:tag ``` -------------------------------- ### Inspect Docker Volume Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Get detailed information about a specific Docker volume, including its mount point on the host. Useful for data persistence issues. ```bash docker volume inspect ``` -------------------------------- ### Manage Docker Compose Services Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Common Docker Compose commands to manage multi-container applications. Use these for starting, stopping, viewing logs, and scaling services. ```bash docker compose up -d # create and start all services (detached) docker compose ps # list running services docker compose logs -f wordpress # follow logs for one service docker compose down # stop and remove containers + networks docker compose down --volumes # also remove named volumes # Scale the web service to 3 instances docker compose up -d --scale web=3 # Validate the compose file docker compose config ``` -------------------------------- ### Build Image with Plain Progress Output Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Build a Docker image and display build progress in a plain text format. Useful for debugging build failures by seeing detailed steps. ```bash docker build --progress=plain -t . ``` -------------------------------- ### Integration Testing Docker Compose Setup Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/015-docker-microservices.md A docker-compose configuration for integration testing. It defines the application service, a test database, and a test runner service that depends on both. ```yaml version: '3' services: app: build: . depends_on: - test-db test-db: image: postgres:13 environment: POSTGRES_DB: test_db POSTGRES_PASSWORD: test_password test: build: context: . dockerfile: Dockerfile.test depends_on: - app - test-db command: ["npm", "run", "test"] ``` -------------------------------- ### Multi-stage Dockerfile for Go applications Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Optimizes Go application Docker images by using a multi-stage build. The build stage compiles the application, and the final stage uses a minimal base image (alpine) to reduce size. ```dockerfile # Multi-stage Go build: strips build toolchain from final image FROM golang:1.16 AS builder WORKDIR /app COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main . FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /root/ COPY --from=builder /app/main . CMD ["./main"] ``` -------------------------------- ### Run a Container with a Bind Mount Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/007-docker-volumes.md Maps a specific directory from the host machine into a container. Ideal for development workflows where host files need to be accessed by the container. ```bash docker run -d --name devtest -v /path/on/host:/app nginx:latest ``` -------------------------------- ### Dockerfile for Flask Model Serving Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/016-docker-ml.md Dockerfile to containerize a Flask application for model serving. It installs dependencies, copies the application code and model, and exposes the application port. ```dockerfile FROM python:3.8 COPY requirements.txt . RUN pip install -r requirements.txt COPY app.py . COPY model.pkl . EXPOSE 5000 CMD ["python", "app.py"] ``` -------------------------------- ### Configure Executable with ENTRYPOINT Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/005-dockerfile.md Configures a container to run as an executable. Often used in combination with CMD, where ENTRYPOINT defines the executable and CMD supplies default arguments. ```dockerfile ENTRYPOINT ["nginx", "-g", "daemon off;"] ``` -------------------------------- ### Start Interactive Shell in Running Container Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Execute a command (like a shell) inside a running container. Useful for interactively debugging a container's environment and processes. ```bash docker exec -it /bin/bash ``` -------------------------------- ### Custom Dockerfile Instructions with ONBUILD Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/013-docker-tips.md Define custom Dockerfile instructions using the ONBUILD instruction, which executes during the image build process of a parent image. ```dockerfile ONBUILD ADD . /app/src ONBUILD RUN /usr/local/bin/python-build --dir /app/src ``` -------------------------------- ### Manage Docker Container Lifecycle Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/003-docker-containers.md Commands to control the state of Docker containers. Use 'stop' and 'start' for running and stopped containers, respectively. 'restart' reboots a container. ```bash docker stop ``` ```bash docker start ``` ```bash docker restart ``` -------------------------------- ### Configure JSON-file Logging Driver with Limits Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/011-docker-performance.md Set up the JSON-file logging driver with options to limit log file size and the number of files to manage disk space. ```yaml version: '3' services: app: image: myapp logging: driver: "json-file" options: max-size: "10m" max-file: "3" ``` -------------------------------- ### Run Docker Container in Interactive Mode Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/003-docker-containers.md Starts a container and attaches your terminal to it, enabling interactive sessions. The '-it' flags are used for interactive mode, often with a shell like /bin/bash. ```bash docker run -it /bin/bash ``` -------------------------------- ### Run cAdvisor for Detailed Metrics Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Deploy and run the cAdvisor container to collect and expose detailed performance metrics for containers and the host. Requires specific volume mounts and port mapping. ```bash docker run \ --volume=/:/rootfs:ro \ --volume=/var/run:/var/run:ro \ --volume=/sys:/sys:ro \ --volume=/var/lib/docker/:/var/lib/docker:ro \ --volume=/dev/disk/:/dev/disk:ro \ --publish=8080:8080 \ --detach=true \ --name=cadvisor \ google/cadvisor:latest ``` -------------------------------- ### View Container Logs Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/012-docker-debugging.md Use this command to view the logs of a specific container. Essential for diagnosing startup failures or runtime errors. ```bash docker logs ``` -------------------------------- ### Docker Compose for resource limits and volumes Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Defines a Docker Compose setup with resource limits (CPU, memory) for a service, uses volume-based storage for a database, and configures capped logging. ```yaml version: '3' services: app: image: myapp deploy: resources: limits: cpus: '0.5' memory: 512M logging: driver: "json-file" options: max-size: "10m" max-file: "3" db: image: postgres volumes: - postgres_data:/var/lib/postgresql/data # volumes > bind mounts for I/O volumes: postgres_data: ``` -------------------------------- ### Configure Healthcheck for a Service Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/008-docker-compose.md Sets up a healthcheck for the 'web' service to verify its availability by sending a curl request to localhost. It specifies the test command, interval, timeout, retries, and start period for the healthcheck. ```yaml version: '3.8' services: web: image: "webapp:latest" healthcheck: test: ["CMD", "curl", "-f", "http://localhost"] interval: 1m30s timeout: 10s retries: 3 start_period: 40s ``` -------------------------------- ### Enable and Open Kubernetes Dashboard Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/010-docker-and-kubernetes.md Enable the Kubernetes Dashboard add-on for Minikube and open it in your browser to access a graphical user interface for managing your cluster. ```bash minikube addons enable dashboard ``` ```bash minikube dashboard ``` -------------------------------- ### Initialize Docker Swarm Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/id/content/099-docker-swarm.md Run this command on the first manager node to initialize a new Docker Swarm cluster. Replace 'your_droplet_ip_here' with the actual IP address of the node. ```bash docker swarm init --advertise-addr your_droplet_ip_here ``` -------------------------------- ### Get Token to Join Swarm as Manager Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/099-docker-swarm.md Execute this command on a manager node to obtain the join token required for other nodes to join the swarm as managers. This token is used to authenticate new managers. ```bash docker swarm join-token manager ``` -------------------------------- ### Docker runtime tuning and monitoring Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Commands for tuning Docker container runtime behavior, such as pinning to CPU cores, using in-memory mounts for temporary data, and overriding DNS. Also includes commands for monitoring container stats and disk usage. ```bash # Runtime tuning docker run --cpuset-cpus="0,1" myapp # pin to specific CPU cores docker run --tmpfs /tmp myapp # in-memory mount for ephemeral data docker run --dns 8.8.8.8 myapp # override DNS resolver # Benchmark & monitor docker stats # live CPU/mem/net/IO per container docker system df # disk usage breakdown ``` -------------------------------- ### Kubernetes Liveness and Readiness Probes Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/011-docker-performance.md Configure liveness and readiness probes for a Kubernetes deployment to ensure application health and availability. ```yaml livenessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 3 periodSeconds: 3 ``` -------------------------------- ### Configure Container Health Check with HEALTHCHECK Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/005-dockerfile.md Use the HEALTHCHECK instruction to define how Docker tests a container's health. This example uses curl to check an HTTP endpoint, failing if the request is unsuccessful. ```dockerfile HEALTHCHECK --interval=30s --timeout=10s CMD curl -f http://localhost/ || exit 1 ``` -------------------------------- ### Get Token to Join Swarm as Worker Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/099-docker-swarm.md Run this command on a manager node to retrieve the join token for worker nodes. This token allows new nodes to join the swarm and perform tasks assigned by managers. ```bash docker swarm join-token worker ``` -------------------------------- ### Initialize Docker Swarm Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/099-docker-swarm.md Run this command on the first manager node to initialize a new Docker Swarm cluster. Replace `your_dorplet_ip_here` with the actual IP address of the node. ```bash docker swarm init --advertise-addr your_dorplet_ip_here ``` -------------------------------- ### Configure Hyperparameter Tuning with Docker Swarm and Optuna Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/016-docker-ml.md Docker Compose file for hyperparameter tuning at scale using Optuna with Docker Swarm. Sets up Optuna workers and a dashboard service. ```yaml version: '3' services: optuna-worker: image: my-optuna-image deploy: replicas: 10 command: ["python", "optimize.py"] optuna-dashboard: image: optuna/optuna-dashboard ports: - "8080:8080" ``` -------------------------------- ### Get Docker Swarm Join Tokens Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Obtain join tokens for adding new manager or worker nodes to the Docker Swarm cluster. Use the manager token for additional managers and the worker token for worker nodes. ```bash # Get join tokens docker swarm join-token manager # for additional managers docker swarm join-token worker # for worker nodes ``` -------------------------------- ### Copy Files with COPY and ADD Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/005-dockerfile.md Copies files from the host into the image. COPY is generally preferred for simplicity, while ADD offers extra features like tar extraction and remote URL support. ```dockerfile COPY package.json . ``` ```dockerfile ADD https://example.com/big.tar.xz /usr/src/things/ ``` -------------------------------- ### Create a Named Volume with a Label Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/007-docker-volumes.md Creates a named volume and assigns a label to it for better organization and management. ```bash docker volume create --label project=myapp my_volume ``` -------------------------------- ### Build Docker Image from Dockerfile Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/004-docker-images.md Build a new Docker image using a Dockerfile in the current directory. The `-t` flag tags the image with a name and optional tag. ```bash docker build -t my-nginx:v1 . ``` -------------------------------- ### Set Up Jupyter Notebook Environment with Docker Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/016-docker-ml.md Use this Dockerfile to create a Python environment with essential data science libraries pre-installed. Exposes port 8888 for Jupyter Notebook access. ```dockerfile FROM python:3.8 RUN pip install jupyter pandas numpy matplotlib scikit-learn WORKDIR /notebooks EXPOSE 8888 CMD ["jupyter", "notebook", "--ip='*'", "--port=8888", "--no-browser", "--allow-root"] ``` -------------------------------- ### Multi-stage Dockerfile for Smaller Images Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/013-docker-tips.md Use multiple FROM statements to reduce the final image size by only including necessary artifacts from the build stage. ```dockerfile # Build stage FROM golang:1.16 AS builder WORKDIR /app COPY . . RUN go build -o main . # Final stage FROM alpine:latest RUN apk --no-cache add ca-certificates WORKDIR /root/ COPY --from=builder /app/main . CMD ["./main"] ``` -------------------------------- ### List and manage Docker images Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Covers fundamental commands for managing Docker images locally and remotely. Includes listing images, pulling specific versions from registries, removing local images, pruning unused images, and tagging images for pushing to a registry. ```bash docker images # list local images (alias: docker image ls) docker pull ubuntu:20.04 # download a specific tag from Docker Hub docker rmi ubuntu:20.04 # remove a local image (alias: docker image rm) docker image prune # remove dangling (untagged) images # Tag an image for pushing to a registry docker tag my-nginx:v1 myuser/my-nginx:v1 # Log in and push docker login docker push myuser/my-nginx:v1 ``` -------------------------------- ### Docker Volume Management Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Manage Docker volumes for data persistence, including creating, listing, inspecting, and removing named volumes. Demonstrates running containers with named volumes, read-only mounts, bind mounts, and tmpfs. Also shows how to back up a volume. ```bash # --- Named volumes (recommended) --- docker volume create my_volume docker volume ls docker volume inspect my_volume docker volume rm my_volume docker volume prune # remove all unused volumes ``` ```bash # Run a container with a named volume docker run -d --name devtest -v my_volume:/app nginx:latest ``` ```bash # Read-only volume mount docker run -d --name devtest -v my_volume:/app:ro nginx:latest ``` ```bash # --- Bind mounts (development) --- docker run -d --name devtest -v /path/on/host:/app nginx:latest ``` ```bash # --- Tmpfs (sensitive / ephemeral data in memory) --- docker run -d --name tmptest --tmpfs /app nginx:latest ``` ```bash # Backup a volume to a tar archive docker run --rm \ -v my_volume:/source \ -v $(pwd):/backup \ ubuntu tar cvf /backup/backup.tar /source ``` -------------------------------- ### Apply Kubernetes Deployment Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/010-docker-and-kubernetes.md Apply the Deployment configuration to your Kubernetes cluster using kubectl. ```bash kubectl apply -f deployment.yaml ``` -------------------------------- ### Follow Logs for a Specific Service Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/008-docker-compose.md Displays the logs for the 'web' service and continues to stream new log output as it appears. ```bash docker compose logs -f web ``` -------------------------------- ### List Docker Networks Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/006-docker-networking.md Lists all available Docker networks on the host. Shows network ID, name, driver, and scope. ```bash docker network ls ``` -------------------------------- ### Combine apt commands in Dockerfile Source: https://context7.com/bobbyiliev/introduction-to-docker-ebook/llms.txt Minimizes Docker image layer count by combining multiple `apt-get` commands into a single `RUN` instruction. Cleans up apt cache afterwards. ```dockerfile # Combine apt commands to minimise layer count RUN apt-get update && apt-get install -y \ package1 \ package2 && rm -rf /var/lib/apt/lists/* ``` -------------------------------- ### Configure Distributed Training with Docker Swarm Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/016-docker-ml.md Docker Compose file to set up a distributed training environment using Docker Swarm. Specifies the image, number of replicas, and the training command. ```yaml version: '3' services: trainer: image: my-ml-image deploy: replicas: 4 command: ["python", "distributed_train.py"] ``` -------------------------------- ### Parallel Docker Testing with GitHub Actions Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/014-docker-ci-cd.md This GitHub Actions workflow demonstrates parallel testing of a Node.js application using Docker, iterating through different Node.js versions. ```yaml # GitHub Actions example jobs: test: runs-on: ubuntu-latest strategy: matrix: node-version: [12.x, 14.x, 16.x] steps: - uses: actions/checkout@v2 - name: Test with Node.js ${{ matrix.node-version }} run: | docker build -t myapp:${{ matrix.node-version }} --build-arg NODE_VERSION=${{ matrix.node-version }} . docker run myapp:${{ matrix.node-version }} npm test ``` -------------------------------- ### Add Docker GPG Key on Ubuntu Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/002-installation.md Add Docker's official GPG key to your system's trusted keys to verify package authenticity. ```bash curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ``` -------------------------------- ### Set Working Directory with WORKDIR Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/005-dockerfile.md Sets the working directory for subsequent instructions like RUN, CMD, ENTRYPOINT, COPY, and ADD. If the directory doesn't exist, it will be created. ```dockerfile WORKDIR /app ``` -------------------------------- ### Docker Swarm Scaling Commands Source: https://github.com/bobbyiliev/introduction-to-docker-ebook/blob/main/ebook/en/content/015-docker-microservices.md Bash commands to initialize a Docker Swarm, deploy a stack defined in a docker-compose.yml file, and scale a specific service within the swarm. ```bash # Initialize swarm docker swarm init # Deploy stack docker stack deploy -c docker-compose.yml myapp # Scale a service docker service scale myapp_service-a=3 ```