Skip to main content

Docker compose

Docker

Fuente: https://docs.docker.com/engine/install/ubuntu/

Quitamos dependencias antiguas

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

Actualizamos repositorios

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Instalamos docker

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Usuario sin sudo

sudo vi /etc/group
docker:x:988:soffid01
sudo systemctl restart docker

sudo usermod -aG docker soffid01

exit > login

docker ps

Docker swarm (hay que descartarlo)

Documentación original: https://bookstack.soffid.com/books/emasa/page/docker-swarm

Ejemplos: https://bookstack.soffid.com/books/postbank/page/configuration-swarm https://bookstack.soffid.com/books/diba/page/diagrama

Para instalar docker swarm hay que crear un fichero.

sudo vi /etc/rc.local

#!/bin/bash
ethtool -K ens3 tx-checksum-ip-generic off
exit

sudo chmod +x /etc/rc.local

sudo reboot

Crear el swarm

docker swarm init

En el principal ejecutar: docker swarm join-token manager

En los secundarios, ejecutar el comando ofrecido

Reiniciar todos los nodos

Soffid01

...

Soffid02

soffid02@soffid02:~$ docker swarm init
Swarm initialized: current node (m3qfgsbfvvzuy7ee5u0seckx4) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-36wzy7p2ryh6pj36btb963oal5r7iyj1jco7h1u4144m3j7cpy-b8tpq6xamse4l2w7wmuhi3eg3 172.16.9.35:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

Crear la red interna.

docker network create  --driver overlay --attachable cluster

#No me ha funcionado y he tenido que crearlo así

soffid02@soffid02:~$ sudo docker network create --driver overlay cluster
xqnwk8k8itc6zfmqoviicd0mi

Docker compose

Documentación: https://bookstack.soffid.com/books/installation/page/installing-soffid

sudo vi docker-compose.yaml

mariadb

version: "3.8"
services:
  mariadb:
    image: mariadb:11.1.2
    environment:
      MYSQL_ROOT_PASSWORD: dkF45.r4f
      MYSQL_DATABASE: soffid
      MYSQL_USER: soffid
      MYSQL_PASSWORD: 98nds.D3
    healthcheck:
      test: "/usr/bin/mariadb --user=root --password=dkF45.r4f --execute \"SHOW DATABASES;\""
      interval: 2s
      timeout: 20s
      retries: 10
    command:
      - --max_allowed_packet=128M
      - --innodb_log_file_size=256M
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_general_ci
    networks:
      - cluster
    volumes:
      - mariadb_data:/var/lib/mysql

networks:
  network:
    name: cluster
    driver: bridge

volumes:
  mariadb_data:
    name: compose_mariadbdata
  console_trust:
    name: compose_console_trustedcerts
  console_conf:
    name: compose_console_conf
  console_logs:
    name: compose_console_logs
  console_index:
    name: compose_console_index
  sync_conf:
    name: compose_sync_conf

Ahora necesitamos continuar con docker

sudo docker compose up -d

WARN[0000] /home/soffid02/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
service "mariadb" refers to undefined network cluster: invalid compose project