docker

This is an old revision of the document!


docker -D info
# docker find by name
docker ps -a --format "{{.ID}} {{.Names}}" --filter name=UismvProd_Db
 
# inspecting docker with jq - mounts
docker inspect   d20d22ecad80 |  jq '.. | objects | with_entries(select(.key | contains("Mounts"))) | select(. != {})'
# inspect restart
docker inspect php4-fpm | jq '.[0] | .. | .RestartPolicy? // empty'
 
#Packages for container
apt install net-tools # - {netstat, ifconfig, iwconfig, route, iptunnel, arp}
apt install iproute2 # - {ss, ip, iw, ip r, ip tunnel, ip n}
apt install procps # - {ps,top}
apt install iputils-ping # - {ping}

Docker. Interface found

$ docker exec -it my-container cat /sys/class/net/eth0/iflink
ip ad | grep 123
#!/bin/bash
 
export containers=$(sudo docker ps --format "{{.ID}}|{{.Names}}")
export interfaces=$(sudo ip ad);
for x in $containers
        do
                export name=$(echo "$x" |cut -d '|' -f 2);
                export id=$(echo "$x"|cut -d '|' -f 1)
                export ifaceNum="$(echo $(sudo docker exec -it "$id" cat /sys/class/net/eth0/iflink) | sed s/[^0-9]*//g):"
                export ifaceStr=$( echo "$interfaces" | grep $ifaceNum | cut -d ':' -f 2 | cut -d '@' -f 1);
                echo -e "$name: $ifaceStr";
done

Docker. Show services table view

$docker ps -a --format "table {{.Names}}\t\t{{.Size}}\t\t{{.Ports}}\t\t{{.Status}}" --filter "label=com.docker.compose.project=docker-reception"
NAMES                                             SIZE                                          PORTS                                                          STATUS
docker-reception_massmess_1                       2B (virtual 44MB)                                                                                            Up 2 months
docker-reception_mysql_1                          1.92kB (virtual 406MB)                        0.0.0.0:3306->3306/tcp                                         Up 3 months
docker-reception_ldr_1                            0B (virtual 14.9MB)                                                                                          Exited (0) 4 minutes ago
mysql-exporter                                    0B (virtual 17.5MB)                           0.0.0.0:9104->9104/tcp                                         Up 3 months
docker-reception_phpgost_1                        769B (virtual 506MB)                          9000/tcp, 0.0.0.0:8080->80/tcp                                 Up 3 months
docker-reception_pma_1                            63.4kB (virtual 89.7MB)                       0.0.0.0:8081->8080/tcp                                         Up 2 months
docker-reception_nginx_1                          2B (virtual 126MB)                            0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp                       Up 3 months

Docker Volume Backup

Docker Volume Restore

Ddocker-compose.yml

  • Process data - find container and do …
#!/usr/bin/env bash
 
#args=("$@")
#echo "args:${args[*]}"
 
LOG=sz_cron_entrypoint_backup.log
 
echo $(date) > $LOG
 
IFS=$'\n'
for line in $(docker ps -a --format "{{.ID}} {{.Names}}" --filter name=UismvProd_Db)
do
        unset IFS
        array=($line)
        echo " Find container name:${array[1]}(id:${array[0]}) -> process wal-g" >> $LOG
        /usr/bin/docker exec  ${array[0]}  /home/wal-g/cron_do_backup.sh >> $LOG
done
  • docker.1664855198.txt.gz
  • Last modified: 2022/10/04 03:46
  • by admin