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

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:
      - network
    volumes:
      - mariadb_data:/var/lib/mysql

  console:
    image: soffid/iam-console:3.6.17
    environment:
      DB_URL: jdbc:mariadb://mariadb/soffid
      DB_USER: soffid
      DB_PASSWORD: 98nds.D3
    ports:
      - 8080:8080
    networks:
    - network
    healthcheck:
      test: bash -c "(echo 'GET /soffid/anonymous/logo.svg HTTP/1.1' >&0; echo >&0; cat >&2;) <> /dev/tcp/localhost/8080"
      interval: 10s
      timeout: 20s
      retries: 10
      start_period: 40s
    volumes:
      - console_trust:/opt/soffid/iam-console-3/trustedcerts
      - console_conf:/opt/soffid/iam-console-3/conf
      - console_logs:/opt/soffid/iam-console-3/logs
      - console_index:/opt/soffid/iam-console-3/index      
    depends_on:
      mariadb:
        condition: service_healthy

  sync-server:
    image: soffid/iam-sync:3.6.14
    hostname: sync-server
    environment:
      SOFFID_PORT: 1760
      SOFFID_HOSTNAME: sync-server.netcompose
      SOFFID_MAIN: yes
      DB_URL: jdbc:mysql://mariadb/soffid
      DB_USER: soffid
      DB_PASSWORD: 98nds.D3
    networks:
      - network
    volumes:
      - sync_conf:/opt/soffid/iam-sync/conf
    depends_on:
      mariadb:
        condition: service_healthy
      console:
        condition: service_healthy

networks:
  network:
    name: netcompose
    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

Iniciamos los contenedorescontenedores.

sudo

docker compose up -d

Comandos útiles.

docker compose ps
docker compose logs -f console
docker compose logs -f sync-server
docker compose exec -it console bash
docker compose exec -it sync-server bash

Para acceder temporalmente a la máquina:

WARN[0000]ssh /home/soffid02/docker-compose.yaml:-L the8080:localhost:8080 attributesoffid01@172.16.9.20

`version`

ssh is-D obsolete,8080 itsoffid01@172.16.9.20

will

 be

ignored,

 please

remove

 it

to

 avoid potential confusion 
service "mariadb" refers to undefined network cluster: invalid compose project