DevOps Classroom notes 23/Sep/2026

Docker secrets:

  • docker secret will be used to store secret information like db password, connection string, artifactory cridenmtals …etc

how it will works

Host ==> /secrets/mysql_db_password.txt
  ||
build == host location 
password=$(cat /secrets/mysql_db_password.txt )

  ||

compose/run 
-v ${pwd}/secrets/mysql_db_password.txt:/app/mysql_db_password.config: ro

  ||

app read/wirte file while runing

permissions

ro: read-only-access
rw: read-wirte-delete access
rwx: read/wirte/excute permissions

How to create secret file

mkdir -p secrets
echo "root_password@123" > secrets/mysql_root_password.txt
echo "root_password@567" > secrets/mysql_password.txt
sudo chmod 600 secrets/*.txt
read - 4
wirte -2
excute -1

       read , wirte , excute 
user   4        2       0       = 6
group  4                        = 4
others                   1      = 1


## symbloic 
chmod u+rwx, o+r , g+rw


--------- file 
-rw-r--r-- 
d---------
drw-r--r--  

How to use it in Docker file

FROM ubuntu:latest

RUN apt update && apt install git -y

WORKDIR src

RUN --mount=type=secret,id=root_password \
    root_password=$(cat /run/secrets/root_password) && \
    echo "root_data is ${root_password}"   
docker build --secret id=root_password,src=./secrets/mysql_root_password.txt  -t demo:1.0 .
version: "1.0"
services:
  mysql:
    image: "mysql:8.0"
    container_name: "mysql_container"
    secrets:
        - source: mysql_root_password
          target: MYSQL_ROOT_PASSWORD
        - source: mysql_user_password
          target: MYSQL_PASSWORD
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=nopcommerce
      - MYSQL_USER=nopuser
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    ports:
      - "3306:3306"
    networks:
      - nop-network
    volumes:
      - mysql-data:/var/lib/mysql
    restart: unless-stopped

volumes:
  mysql-data:


networks:
  nop-network:
    driver: bridge

secrets:
  mysql_root_password:
    file: ./secrets/mysql_root_password.txt
  mysql_user_password:
    file: ./secrets/mysql_user_password.txt

Task

  1. create secrect file and use it docker fil
  2. create git pat token
git clone https://<username>:<PAT>@github.com/<username>/<repository>.git

git clone https://ramjagadeesh2205:ghapatken@github.com/ramjagadeesh2205/demo-repo.git

RUN --mount=type=secret,id=github_pat \
    github_pat=$(cat /run/secrets/github_pat.txt) && \
    git clone https://ramjagadeesh2205:${github_pat}@github.com/ramjagadeesh2205/demo-repo.git

Task:2

  1. create acr/ECR
  2. build image and push to acr/ECR

ACR REF

ECR REF

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%