Page 1 of 1

Docker sysadmin

Posted: 2024 Feb 19, 11:37
by Mihai
This list will be upgraded with time.
  • Update all images:

Code: Select all

docker images | grep -v REPOSITORY | awk '{print $1}' | xargs -L1 docker pull
  • Remove all images with no tags ( <none> ):

Code: Select all

docker image ls | egrep none | awk '{print $3}' | xargs docker image rm
  • Show disk usage detailed

Code: Select all

docker system df -v
  • Show IP address for every container ( docker-compose only )

Code: Select all

docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
  • Show IP address for every container

Code: Select all

docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}} %tab% {{.Name}}' $(docker ps -aq ) | sed 's#%tab%#\t#g' | sed 's#/##g' | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n
  • Create bridge network

Code: Select all

docker network create --driver=bridge --subnet=172.28.0.0/16 --ip-range=172.28.5.0/24 --gateway=172.28.5.254 br0
  • Create MacVLAN network with ip-range

Code: Select all

docker network create -d macvlan --subnet=192.168.0.0/24 --gateway=192.168.0.1  --ip-range=192.168.0.64/26 -o parent=eth0 public_network_mac_vlan
IP Range will be:

Code: Select all

HostMin:   	192.168.0.65          		11000000.10101000.00000000.01 000001
HostMax:   	192.168.0.126         		11000000.10101000.00000000.01 111110
  • Create and activate heathcheck user mariadb
Create filename .my-healthcheck.cnf in the root directory of the docker application and add the following content inside:

Code: Select all

[mariadb-client]
port=3306
socket=/run/mysqld/mysqld.sock
user=healthcheck
password=addYouRPas55W0rDH3R3
protocol=tcp
Link filename in volumes for your application:

Code: Select all

/apps/docker/docker-containers/application-name/.my-healthcheck.cnf:/var/lib/mysql/.my-healthcheck.cnf
Add username healthcheck in your database and grant minimal privileges:

Code: Select all

CREATE USER 'healthcheck'@'localhost' IDENTIFIED BY 'addYouRPas55W0rDH3R3';
CREATE USER 'healthcheck'@'127.0.0.1' IDENTIFIED BY 'addYouRPas55W0rDH3R3';
GRANT USAGE ON *.* TO 'healthcheck'@'localhost';
GRANT USAGE ON *.* TO 'healthcheck'@'127.0.0.1';
Add configuration to docker-compose.yml under the DB app:

Code: Select all

    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
      start_period: 10s
      interval: 10s
      timeout: 5s
      retries: 3
Result will be similar to the following:

Code: Select all

CONTAINER ID    IMAGE                 COMMAND                      CREATED           STATUS                            PORTS        NAMES
38d083416ca8    mariadb:latest        docker-entrypoint.s…"        8 minutes ago     Up 8 minutes (healthy)            3306/tcp     mariadb_test_app