├── .DS_Store ├── Docker Swarm Stack_Deployment ├── .DS_Store ├── Docker-Project.zip ├── docker-compose-YAML.txt ├── docker-compose-yml_Persistent_Data.txt └── docker-stack-YAML_distributed_Application.TXT ├── Docker_Container_Images_Build Images ├── .DS_Store ├── dockerfile_Assignment_Build_Image.txt ├── dockerfile_CustomImage.txt ├── dockerfile_Extent_Official_Image.txt └── my-script.py ├── Docker_Swarm_Secrets_Management ├── .DS_Store └── docker-compse.yml.txt ├── README.md ├── docker_compose_build_image ├── app.js ├── app.py ├── docker-compose.yml ├── dockerfile.node └── dockerfile.python ├── docker_compose_custom_app ├── .DS_Store ├── Custom-Application.yml ├── app.js ├── dockerfile └── package.json ├── docker_compose_wordpress_mysql └── docker-compose.yml ├── docker_stack_distributed_app └── docker-stack.yml ├── docker_stack_with_secrets ├── docker-stack-updated.yml ├── docker-stack.yml ├── postgres_password └── postgres_user ├── docker_swarm_healthcheck └── docker-stack.yml ├── docker_swarm_node_constraints └── docker-stack.yml ├── docker_swarm_visualizer └── docker-compose.yml └── docker_webapp_stack ├── app.py ├── docker-compose.yml ├── docker-compose_updated_redis.yml ├── dockerfile └── requirements.txt /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anshulc55/Docker_for_DevOps/93c751b727cd3d95086407443c6f2df3f62065f8/.DS_Store -------------------------------------------------------------------------------- /Docker Swarm Stack_Deployment/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anshulc55/Docker_for_DevOps/93c751b727cd3d95086407443c6f2df3f62065f8/Docker Swarm Stack_Deployment/.DS_Store -------------------------------------------------------------------------------- /Docker Swarm Stack_Deployment/Docker-Project.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anshulc55/Docker_for_DevOps/93c751b727cd3d95086407443c6f2df3f62065f8/Docker Swarm Stack_Deployment/Docker-Project.zip -------------------------------------------------------------------------------- /Docker Swarm Stack_Deployment/docker-compose-YAML.txt: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | # Service Name Defined as web 4 | web: 5 | # Pull the Image from Repository. 6 | # replace username/repo:tag with your name and image details 7 | image: anshuldevops/frindly_hello:latest 8 | # Command used to deploy the Service 9 | deploy: 10 | # Run 5 instances of that image as a service called web 11 | replicas: 5 12 | resources: 13 | # Limiting each one to use, at most, 10% of a single core of CPU time and 50MB of RAM. 14 | limits: 15 | cpus: "0.1" 16 | memory: 50M 17 | # Immediately restart containers if one fails. 18 | restart_policy: 19 | condition: on-failure 20 | # Map port 4000 on the host to web’s port 80. 21 | ports: 22 | - "4000:80" 23 | # Define default network 24 | networks: 25 | - webnet 26 | 27 | visualizer: 28 | image: dockersamples/visualizer:stable 29 | ports: 30 | - "8080:8080" 31 | volumes: 32 | - "/var/run/docker.sock:/var/run/docker.sock" 33 | deploy: 34 | placement: 35 | constraints: [node.role == manager] 36 | networks: 37 | - webnet 38 | networks: 39 | webnet: -------------------------------------------------------------------------------- /Docker Swarm Stack_Deployment/docker-compose-yml_Persistent_Data.txt: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | # Service Name Defined as web 4 | web: 5 | # Pull the Image from Repository. 6 | # replace username/repo:tag with your name and image details 7 | image: anshuldevops/frindly_hello:latest 8 | # Command used to deploy the Service 9 | deploy: 10 | # Run 5 instances of that image as a service called web 11 | replicas: 5 12 | resources: 13 | # Limiting each one to use, at most, 10% of a single core of CPU time and 50MB of RAM. 14 | limits: 15 | cpus: "0.1" 16 | memory: 50M 17 | # Immediately restart containers if one fails. 18 | restart_policy: 19 | condition: on-failure 20 | # Map port 4000 on the host to web’s port 80. 21 | ports: 22 | - "4000:80" 23 | # Define default network 24 | networks: 25 | - webnet 26 | 27 | visualizer: 28 | image: dockersamples/visualizer:stable 29 | ports: 30 | - "8080:8080" 31 | volumes: 32 | - "/var/run/docker.sock:/var/run/docker.sock" 33 | deploy: 34 | placement: 35 | constraints: [node.role == manager] 36 | networks: 37 | - webnet 38 | 39 | redis: 40 | image: redis 41 | ports: 42 | - "6379:6379" 43 | volumes: 44 | - "/home/docker/data:/data" 45 | deploy: 46 | placement: 47 | constraints: [node.role == manager] 48 | command: redis-server --appendonly yes 49 | networks: 50 | - webnet 51 | networks: 52 | webnet: -------------------------------------------------------------------------------- /Docker Swarm Stack_Deployment/docker-stack-YAML_distributed_Application.TXT: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | 4 | redis: 5 | image: redis:alpine 6 | networks: 7 | - frontend 8 | deploy: 9 | replicas: 1 10 | update_config: 11 | parallelism: 2 12 | delay: 10s 13 | restart_policy: 14 | condition: on-failure 15 | 16 | db: 17 | image: postgres:9.4 18 | volumes: 19 | - db-data:/var/lib/postgresql/data 20 | networks: 21 | - backend 22 | deploy: 23 | placement: 24 | constraints: [node.role == manager] 25 | 26 | vote: 27 | image: dockersamples/examplevotingapp_vote:before 28 | ports: 29 | - 5000:80 30 | networks: 31 | - frontend 32 | depends_on: 33 | - redis 34 | deploy: 35 | replicas: 2 36 | update_config: 37 | parallelism: 2 38 | restart_policy: 39 | condition: on-failure 40 | 41 | result: 42 | image: dockersamples/examplevotingapp_result:before 43 | ports: 44 | - 5001:80 45 | networks: 46 | - backend 47 | depends_on: 48 | - db 49 | deploy: 50 | replicas: 1 51 | update_config: 52 | parallelism: 2 53 | delay: 10s 54 | restart_policy: 55 | condition: on-failure 56 | 57 | worker: 58 | image: dockersamples/examplevotingapp_worker 59 | networks: 60 | - frontend 61 | - backend 62 | depends_on: 63 | - db 64 | deploy: 65 | mode: replicated 66 | replicas: 1 67 | labels: [APP=VOTING] 68 | restart_policy: 69 | condition: on-failure 70 | delay: 10s 71 | max_attempts: 3 72 | window: 120s 73 | placement: 74 | constraints: [node.role == manager] 75 | 76 | visualizer: 77 | image: dockersamples/visualizer:stable 78 | ports: 79 | - "8080:8080" 80 | stop_grace_period: 1m30s 81 | volumes: 82 | - "/var/run/docker.sock:/var/run/docker.sock" 83 | deploy: 84 | placement: 85 | constraints: [node.role == manager] 86 | 87 | networks: 88 | frontend: 89 | backend: 90 | 91 | volumes: 92 | db-data: -------------------------------------------------------------------------------- /Docker_Container_Images_Build Images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anshulc55/Docker_for_DevOps/93c751b727cd3d95086407443c6f2df3f62065f8/Docker_Container_Images_Build Images/.DS_Store -------------------------------------------------------------------------------- /Docker_Container_Images_Build Images/dockerfile_Assignment_Build_Image.txt: -------------------------------------------------------------------------------- 1 | # Each instruction in this file generates a new layer that gets pushed to your local image cache 2 | FROM python:latest 3 | 4 | # Identify the maintainer of an image 5 | LABEL version="0.0.1" 6 | LABEL maitainer="anshulc55@gmail.com" 7 | 8 | # Add Python Script 9 | ADD my_script.py / 10 | 11 | # Execute python script 12 | CMD [ "python", "./my_script.py" ] -------------------------------------------------------------------------------- /Docker_Container_Images_Build Images/dockerfile_CustomImage.txt: -------------------------------------------------------------------------------- 1 | # Each instruction in this file generates a new layer that gets pushed to your local image cache 2 | # The line below states we will base our new image on the Latest Official Ubuntu 3 | FROM ubuntu:latest 4 | 5 | # Identify the maintainer of an image 6 | LABEL version="0.0.1" 7 | LABEL maitainer="anshulc55@gmail.com" 8 | 9 | # Update the image to the latest packages 10 | RUN apt-get update && apt-get upgrade -y 11 | 12 | # Install NGINX to test. 13 | RUN apt-get install nginx -y 14 | 15 | # Expose port 80 16 | EXPOSE 80 17 | 18 | # Last is the actual command to start up NGINX within our Container 19 | CMD [ "nginx", "-g", "daemon off;"] -------------------------------------------------------------------------------- /Docker_Container_Images_Build Images/dockerfile_Extent_Official_Image.txt: -------------------------------------------------------------------------------- 1 | # Each instruction in this file generates a new layer that gets pushed to your local image cache 2 | # The line below states we will base our new image on the Latest Official Ubuntu 3 | FROM nginx:latest 4 | 5 | # Identify the maintainer of an image 6 | LABEL version="0.0.1" 7 | LABEL maitainer="anshulc55@gmail.com" 8 | 9 | # Updateing the work DIR 10 | WORKDIR /usr/share/nginx/html 11 | 12 | # Replace Index.html with Custom file 13 | COPY index.html index.html -------------------------------------------------------------------------------- /Docker_Container_Images_Build Images/my-script.py: -------------------------------------------------------------------------------- 1 | n=15 2 | for i in range(0,n): 3 | print (((n-(i+1))*' ')+(((2*i)+1)*'*')) 4 | for i in range(1,n): 5 | print (((i)*' ')+(((((n-i)*2)-1)*'*'))) -------------------------------------------------------------------------------- /Docker_Swarm_Secrets_Management/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anshulc55/Docker_for_DevOps/93c751b727cd3d95086407443c6f2df3f62065f8/Docker_Swarm_Secrets_Management/.DS_Store -------------------------------------------------------------------------------- /Docker_Swarm_Secrets_Management/docker-compse.yml.txt: -------------------------------------------------------------------------------- 1 | version: "3.1" 2 | services: 3 | # Service Name Defined as web 4 | postgresDB: 5 | # Pull the Image from Repository. 6 | image: postgres:latest 7 | # Command to use secrects in 8 | secrets: 9 | # define Secrets name 10 | - db_username 11 | - db_password 12 | environment: 13 | # Define environment varaibles 14 | POSTGRES_PASSWORD_FILE: /run/secrets/db_password 15 | POSTGRES_USER_FILE: /run/secrets/db_username 16 | 17 | centOS: 18 | image: centos 19 | deploy: 20 | replicas: 1 21 | entrypoint: /bin/sh 22 | stdin_open: true 23 | tty: true 24 | secrets: 25 | - source: my-secret 26 | 27 | 28 | secrets: 29 | db_username: 30 | file: ./postgres_user.txt 31 | db_password: 32 | file: ./postgres_password.txt 33 | my-secret: 34 | external: true -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker for DevOps 2 | 3 | This repository provides a collection of Docker configurations and resources tailored for DevOps practices. It aims to simplify the integration of Docker into the DevOps workflow, providing a foundation for containerized development, testing, and deployment. 4 | 5 | ## Table of Contents 6 | 7 | - [Introduction](#introduction) 8 | - [Prerequisites](#prerequisites) 9 | - [Getting Started](#getting-started) 10 | - [Directory Structure](#directory-structure) 11 | - [Usage](#usage) 12 | - [Contributing](#contributing) 13 | - [License](#license) 14 | 15 | ## Introduction 16 | 17 | Docker for DevOps is designed to streamline the implementation of Docker in a DevOps environment. It includes Docker configurations, sample Dockerfiles, and guidelines to help you build, test, and deploy applications using Docker containers. Whether you are new to Docker or an experienced user, this repository provides a foundation for incorporating Docker into your DevOps practices. 18 | 19 | ## Prerequisites 20 | 21 | Before you start using the Docker configurations and resources in this repository, make sure you have the following prerequisites installed on your system: 22 | 23 | - Docker: [Install Docker](https://docs.docker.com/get-docker/) 24 | - Docker Compose: [Install Docker Compose](https://docs.docker.com/compose/install/) 25 | 26 | ## Getting Started 27 | 28 | To get started with Docker for DevOps, follow these steps: 29 | 30 | 1. Clone the repository: 31 | 32 | ```bash 33 | git clone https://github.com/anshulc55/Docker_for_DevOps.git 34 | ``` 35 | 36 | 2. Navigate to the repository directory: 37 | 38 | ```bash 39 | cd Docker_for_DevOps 40 | ``` 41 | 42 | 3. Explore the provided Docker configurations, sample Dockerfiles, and resources tailored for DevOps. 43 | 44 | ## Directory Structure 45 | 46 | The repository has the following directory structure: 47 | 48 | - `dockerfiles/`: Contains sample Dockerfiles for various types of applications. 49 | - `configurations/`: Includes Docker Compose files and configuration files for different scenarios. 50 | - `resources/`: Additional resources such as scripts, tools, or templates to support Docker in DevOps. 51 | 52 | ## Usage 53 | 54 | Explore the provided Docker configurations and resources to integrate Docker into your DevOps workflow. Refer to the specific documentation within each directory for detailed instructions on how to use the Docker configurations for your applications. 55 | 56 | ## Contributing 57 | 58 | If you would like to contribute to this project, follow these steps: 59 | 60 | 1. Fork the repository. 61 | 2. Create a new branch for your feature or bug fix: `git checkout -b feature/your-feature` or `git checkout -b bugfix/your-bugfix`. 62 | 3. Make your changes and commit them with a clear message. 63 | 4. Push your changes to your fork. 64 | 5. Submit a pull request to the `main` branch of the original repository. 65 | 66 | ## License 67 | 68 | This project is licensed under the [MIT License](LICENSE), which means you are free to use, modify, and distribute the code as long as the original license and copyright notice are included. See the [LICENSE](LICENSE) file for more details. 69 | -------------------------------------------------------------------------------- /docker_compose_build_image/app.js: -------------------------------------------------------------------------------- 1 | // app.js 2 | const appName = process.env.APP_NAME || 'Unknown'; 3 | const environment = process.env.ENVIRONMENT || 'Unknown'; 4 | 5 | console.log(`Running ${appName} in ${environment} environment.`); -------------------------------------------------------------------------------- /docker_compose_build_image/app.py: -------------------------------------------------------------------------------- 1 | # app.py 2 | import os 3 | 4 | app_version = os.environ.get('APP_VERSION', 'Unknown') 5 | environment = os.environ.get('ENVIRONMENT', 'Unknown') 6 | 7 | print(f"Running App version {app_version} in {environment} environment.") -------------------------------------------------------------------------------- /docker_compose_build_image/docker-compose.yml: -------------------------------------------------------------------------------- 1 | # docker-compose.yml 2 | version: '3' 3 | services: 4 | python_service: 5 | build: 6 | context: . 7 | dockerfile: dockerfile.python 8 | args: 9 | - BASE_IMAGE=python:3.9 10 | - APP_VERSION=2.0 11 | environment: 12 | - DEBUG=true 13 | image: anshuldevops/python_web:2.1 14 | 15 | node_service: 16 | build: 17 | context: . 18 | dockerfile: dockerfile.node 19 | args: 20 | - BASE_IMAGE=node:21 21 | - APP_NAME=my-nodejs-app 22 | environment: 23 | - NODE_ENV=development 24 | image: anshuldevops/node_web:2.1 25 | -------------------------------------------------------------------------------- /docker_compose_build_image/dockerfile.node: -------------------------------------------------------------------------------- 1 | # Dockerfile2 2 | ARG BASE_IMAGE 3 | FROM ${BASE_IMAGE} 4 | 5 | WORKDIR /app 6 | 7 | # Accept dynamic argument 8 | ARG APP_NAME 9 | ENV APP_NAME=${APP_NAME} 10 | 11 | # Set environment variable 12 | ENV ENVIRONMENT=development 13 | 14 | COPY . . 15 | 16 | CMD ["node", "app.js"] -------------------------------------------------------------------------------- /docker_compose_build_image/dockerfile.python: -------------------------------------------------------------------------------- 1 | # Dockerfile1 2 | ARG BASE_IMAGE 3 | FROM ${BASE_IMAGE} 4 | 5 | WORKDIR /app 6 | 7 | # Accept dynamic argument 8 | ARG APP_VERSION 9 | ENV APP_VERSION=${APP_VERSION} 10 | 11 | # Set environment variable 12 | ENV ENVIRONMENT=production 13 | 14 | COPY . . 15 | 16 | CMD ["python", "app.py"] -------------------------------------------------------------------------------- /docker_compose_custom_app/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/anshulc55/Docker_for_DevOps/93c751b727cd3d95086407443c6f2df3f62065f8/docker_compose_custom_app/.DS_Store -------------------------------------------------------------------------------- /docker_compose_custom_app/Custom-Application.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | node-app: 4 | build: 5 | context: . 6 | ports: 7 | - "3000:3000" 8 | depends_on: 9 | - mongo 10 | image: anshuldevops/custom_nodeapp:1.0 11 | 12 | mongo: 13 | image: mongo:latest 14 | ports: 15 | - "27017:27017" 16 | -------------------------------------------------------------------------------- /docker_compose_custom_app/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const mongoose = require('mongoose'); 3 | const { exec } = require('child_process'); 4 | 5 | const app = express(); 6 | const PORT = 3000; 7 | 8 | // MongoDB connection 9 | mongoose.connect('mongodb://mongo:27017/mydatabase', { useNewUrlParser: true, useUnifiedTopology: true }); 10 | 11 | const db = mongoose.connection; 12 | db.on('error', console.error.bind(console, 'MongoDB connection error:')); 13 | db.once('open', () => { 14 | console.log('Connected to MongoDB'); 15 | }); 16 | 17 | // Docker Compose up 18 | const startContainers = () => { 19 | exec('docker-compose up -d', (error, stdout, stderr) => { 20 | if (error) { 21 | console.error(`Error starting containers: ${error.message}`); 22 | return; 23 | } 24 | console.log(`Containers started successfully:\n${stdout}`); 25 | }); 26 | }; 27 | 28 | // Express route to start containers 29 | app.get('/start-containers', (req, res) => { 30 | startContainers(); 31 | res.send('Containers are starting...'); 32 | }); 33 | 34 | // Express route to check if containers are running 35 | app.get('/check-containers', (req, res) => { 36 | exec('docker ps', (error, stdout, stderr) => { 37 | if (error) { 38 | console.error(`Error checking containers: ${error.message}`); 39 | res.send('Error checking containers'); 40 | return; 41 | } 42 | res.send(`Containers running:\n${stdout}`); 43 | }); 44 | }); 45 | 46 | // Start the Express server 47 | app.listen(PORT, () => { 48 | console.log(`Server is running on http://localhost:${PORT}`); 49 | }); 50 | -------------------------------------------------------------------------------- /docker_compose_custom_app/dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:14 2 | 3 | WORKDIR /usr/src/app 4 | 5 | COPY package*.json ./ 6 | 7 | RUN npm install 8 | 9 | COPY . . 10 | 11 | EXPOSE 3000 12 | 13 | CMD ["node", "app.js"] 14 | -------------------------------------------------------------------------------- /docker_compose_custom_app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "my-node-app", 3 | "version": "1.0.0", 4 | "main": "app.js", 5 | "dependencies": { 6 | "express": "^4.17.1", 7 | "mongoose": "^6.1.5" 8 | }, 9 | "scripts": { 10 | "start": "node app.js" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /docker_compose_wordpress_mysql/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' #Version of YML file 2 | 3 | services: 4 | # MySQL Service 5 | db: 6 | image: mysql:5.7 7 | container_name: mysql-container 8 | restart: always 9 | environment: 10 | MYSQL_ROOT_PASSWORD: mypassword 11 | MYSQL_DATABASE: wordpress 12 | MYSQL_USER: wordpressuser 13 | MYSQL_PASSWORD: wordpress 14 | volumes: 15 | - mysql_data:/var/lib/mysql 16 | networks: 17 | - wordpress_network 18 | ports: 19 | - "3306:3306" 20 | 21 | # WordPress Service 22 | wordpress: 23 | depends_on: 24 | - db 25 | image: wordpress:latest 26 | container_name: wordpress-container 27 | restart: always 28 | environment: 29 | WORDPRESS_DB_HOST: db:3306 30 | WORDPRESS_DB_USER: wordpressuser 31 | WORDPRESS_DB_PASSWORD: wordpress 32 | volumes: 33 | - wordpress_data:/var/www/html 34 | ports: 35 | - "8080:80" 36 | networks: 37 | - wordpress_network 38 | 39 | volumes: 40 | mysql_data: 41 | wordpress_data: 42 | 43 | networks: 44 | wordpress_network: 45 | driver: bridge 46 | -------------------------------------------------------------------------------- /docker_stack_distributed_app/docker-stack.yml: -------------------------------------------------------------------------------- 1 | # this file is meant for Docker Swarm stacks only 2 | # trying it in compose will fail because of multiple replicas trying to bind to the same port 3 | # Swarm currently does not support Compose Spec, so we'll pin to the older version 3.9 4 | 5 | version: "3.9" 6 | 7 | services: 8 | 9 | redis: 10 | image: redis:alpine 11 | networks: 12 | - frontend 13 | 14 | db: 15 | image: postgres:15-alpine 16 | environment: 17 | POSTGRES_USER: "postgres" 18 | POSTGRES_PASSWORD: "postgres" 19 | volumes: 20 | - db-data:/var/lib/postgresql/data 21 | networks: 22 | - backend 23 | 24 | vote: 25 | image: dockersamples/examplevotingapp_vote 26 | ports: 27 | - 5000:80 28 | networks: 29 | - frontend 30 | deploy: 31 | replicas: 2 32 | 33 | result: 34 | image: dockersamples/examplevotingapp_result 35 | ports: 36 | - 5001:80 37 | networks: 38 | - backend 39 | 40 | worker: 41 | image: dockersamples/examplevotingapp_worker 42 | networks: 43 | - frontend 44 | - backend 45 | deploy: 46 | replicas: 2 47 | 48 | networks: 49 | frontend: 50 | backend: 51 | 52 | volumes: 53 | db-data: -------------------------------------------------------------------------------- /docker_stack_with_secrets/docker-stack-updated.yml: -------------------------------------------------------------------------------- 1 | version: "3.1" 2 | services: 3 | # Service Name Defined as web 4 | postgresDB: 5 | # Pull the Image from Repository. 6 | image: postgres:latest 7 | # Command to use secrects in 8 | secrets: 9 | # define Secrets name 10 | - db_username 11 | - db_password 12 | environment: 13 | # Define environment varaibles 14 | POSTGRES_PASSWORD_FILE: /run/secrets/db_password 15 | POSTGRES_USER_FILE: /run/secrets/db_username 16 | 17 | centOS: 18 | image: centos 19 | deploy: 20 | replicas: 1 21 | entrypoint: /bin/sh 22 | stdin_open: true 23 | tty: true 24 | secrets: 25 | - source: my-secret 26 | 27 | 28 | secrets: 29 | db_username: 30 | file: ./postgres_user.txt 31 | db_password: 32 | file: ./postgres_password.txt 33 | my-secret: 34 | external: true -------------------------------------------------------------------------------- /docker_stack_with_secrets/docker-stack.yml: -------------------------------------------------------------------------------- 1 | version: "3.9" 2 | services: 3 | # Service Name Defined as web 4 | postgresDB: 5 | # Pull the Image from Repository. 6 | image: postgres:latest 7 | # Command to use secrects in 8 | secrets: 9 | # define Secrets name 10 | - db_username 11 | - db_password 12 | environment: 13 | # Define environment varaibles 14 | POSTGRES_PASSWORD_FILE: /run/secrets/db_password 15 | POSTGRES_USER_FILE: /run/secrets/db_username 16 | 17 | secrets: 18 | db_username: 19 | file: ./postgres_user 20 | db_password: 21 | file: ./postgres_password -------------------------------------------------------------------------------- /docker_stack_with_secrets/postgres_password: -------------------------------------------------------------------------------- 1 | postgress_pass@123 -------------------------------------------------------------------------------- /docker_stack_with_secrets/postgres_user: -------------------------------------------------------------------------------- 1 | postgress -------------------------------------------------------------------------------- /docker_swarm_healthcheck/docker-stack.yml: -------------------------------------------------------------------------------- 1 | version: '3.9' 2 | 3 | services: 4 | postgres: 5 | image: postgres:latest 6 | environment: 7 | POSTGRES_USER: postgress_user 8 | POSTGRES_PASSWORD: db_password123 9 | POSTGRES_DB: sample_db 10 | ports: 11 | - "5432:5432" 12 | deploy: 13 | replicas: 1 14 | update_config: 15 | parallelism: 1 16 | delay: 10s 17 | restart_policy: 18 | condition: on-failure 19 | delay: 5s 20 | max_attempts: 3 21 | window: 120s 22 | healthcheck: 23 | test: ["CMD-SHELL", "pg_isready -U postgress_user -d sample_db -h localhost -p 5432"] 24 | interval: 30s 25 | timeout: 10s 26 | retries: 3 27 | -------------------------------------------------------------------------------- /docker_swarm_node_constraints/docker-stack.yml: -------------------------------------------------------------------------------- 1 | version: '3.8' 2 | 3 | services: 4 | webapp: 5 | image: your_webapp_image:latest 6 | ports: 7 | - "80:80" 8 | deploy: 9 | replicas: 3 10 | placement: 11 | constraints: 12 | - node.role == worker 13 | - node.labels.environment == production 14 | - node.labels.zone == east 15 | -------------------------------------------------------------------------------- /docker_swarm_visualizer/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | visualizer: 5 | image: dockersamples/visualizer:stable 6 | container_name: swarm-visualizer 7 | ports: 8 | - "8090:8080" 9 | volumes: 10 | - "/var/run/docker.sock:/var/run/docker.sock" 11 | deploy: 12 | placement: 13 | constraints: 14 | - node.role == manager 15 | -------------------------------------------------------------------------------- /docker_webapp_stack/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from redis import Redis, RedisError 3 | import os 4 | import socket 5 | 6 | # Connect to Redis 7 | redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2) 8 | 9 | app = Flask(__name__) 10 | 11 | @app.route("/") 12 | def hello(): 13 | try: 14 | visits = redis.incr("counter") 15 | except RedisError: 16 | visits = "cannot connect to Redis, counter disabled" 17 | 18 | html = "