ict-architecture
Labo 02: Vervolg Docker Swarm
Werken met Docker Configs, Secrets en volumes in Swarm Mode.
Configs & Secrets
docker config create mysql_init_script init.sqlMaak een Docker config aan vanuit een lokaal bestand.
docker service update --config-rm mysql_init_script --config-add source=mysql_init_script_v2,target=/docker-entrypoint-initdb.d/init.sql mysql-serviceUpdate een service om een nieuwe config te gebruiken (configs zijn immutable).
echo "mijn_wachtwoord" | docker secret create mysql_root_password -Maak een Docker secret aan.
Schalen & Herstel
docker rm -f <CONTAINER_ID>Forceer het verwijderen van een container om Swarm's self-healing te testen.
docker service scale mysql-secure=2Schaal een service handmatig op of af.
Bestanden & Configuraties
init.sql
sql
CREATE DATABASE IF NOT EXISTS ApplicationDB;USE ApplicationDB;CREATE TABLE IF NOT EXISTS ApplicationData ( id INT AUTO_INCREMENT PRIMARY KEY, data_value VARCHAR(255)); INSERT INTO ApplicationData (data_value) VALUES ('Eerste record');SQL opstartscript voor MySQL database.
mysql-stack.yaml
yaml
version: '3.8'services: db: image: mysql:8.0 environment: MYSQL_ROOT_PASSWORD_FILE: /run/secrets/mysql_root_password MYSQL_DATABASE: ApplicationDB secrets: - mysql_root_password configs: - source: mysql_init_script target: /docker-entrypoint-initdb.d/init.sql deploy: replicas: 1configs: mysql_init_script: file: ./init.sqlsecrets: mysql_root_password: external: trueStack file met MySQL, Configs en Secrets configuratie.