This shows you the differences between two versions of the page.
moby:backend:07 [2020/08/12 15:18] alexandru.hogea |
moby:backend:07 [2020/08/12 15:24] (current) alexandru.hogea [Exercitii] |
||
---|---|---|---|
Line 66: | Line 66: | ||
=== Exemplu de fisier docker-compose.yml === | === Exemplu de fisier docker-compose.yml === | ||
- | <code yml> | + | <code yaml> |
# docker-compose.yml | # docker-compose.yml | ||
Line 110: | Line 110: | ||
</code> | </code> | ||
=== Proprietati in cadrul unui fisier docker-compose.yml === | === Proprietati in cadrul unui fisier docker-compose.yml === | ||
- | <code yml> | + | <code yaml> |
### Exemple de build pentru imagini | ### Exemple de build pentru imagini | ||
web: | web: | ||
Line 158: | Line 158: | ||
- ./data:/var/lib/mysql # Se mapeaza fisierul sau folderul local la ce din container | - ./data:/var/lib/mysql # Se mapeaza fisierul sau folderul local la ce din container | ||
- named_volume:/var/lib/mysql | - named_volume:/var/lib/mysql | ||
- | - | + | |
### Network | ### Network | ||
- | |||
# Se creaza o noua retea | # Se creaza o noua retea | ||
networks: | networks: | ||
- frontend | - frontend | ||
- | ### External network | + | ### Secrets |
+ | secrets: | ||
+ | - my_awesome_secret | ||
+ | </code> | ||
+ | <note important>Cand introduceti un **named volume**, **o retea** sau **un secret**, nu uitati sa le declarati si la finalul fisierului .yml in sectiunile speciale (volumes, networks, secrets)</note> | ||
+ | |||
+ | === Exemplu de docker-compose.yml pentru serviciul "Library" === | ||
+ | <code yaml> | ||
+ | version: "3.8" | ||
+ | |||
+ | services: | ||
+ | library-service: | ||
+ | build: '../' | ||
+ | environment: | ||
+ | NODE_ENV: staging | ||
+ | PGHOST: localhost | ||
+ | PGUSER_FILE: workshop-library-pguser-secret | ||
+ | PGPASSWORD_FILE: workshop-library-pgpassword-secret | ||
+ | PGPORT: 5432 | ||
+ | PGDATABASE: ${PGDATABASE} | ||
+ | AUTH_SERVICE: ${AUTH_SERVICE} | ||
+ | NOTIFICATION_SERVICE: ${NOTIFICATION_SERVICE} | ||
+ | ADMIN_ROLE: ${ADMIN_ROLE} | ||
+ | READER_ROLE: ${READER_ROLE} | ||
+ | volumes: | ||
+ | - ../:/usr/src/app | ||
+ | command: ["npm", "run", "start-dev-docker"] | ||
+ | networks: | ||
+ | - library_internal | ||
+ | - cluster | ||
+ | secrets: | ||
+ | - workshop-library-pguser-secret | ||
+ | - workshop-library-pgpassword-secret | ||
+ | |||
+ | db: | ||
+ | image: postgres | ||
+ | environment: | ||
+ | POSTGRES_USER_FILE: /run/secrets/workshop-library-pguser-secret | ||
+ | POSTGRES_PASSWORD: /run/secrets/workshop-library-pgpassword-secret | ||
+ | POSTGRES_DB: ${PGDATABASE} | ||
+ | TZ: Europe/Bucharest | ||
+ | PGTZ: Europe/Bucharest | ||
+ | volumes: | ||
+ | - workshop-library:/var/lib/postgresql/data | ||
+ | - ./init.sql:/docker-entrypoint-initdb.d/init.sql | ||
+ | networks: | ||
+ | - library_internal | ||
+ | secrets: | ||
+ | - workshop-library-pguser-secret | ||
+ | - workshop-library-pgpassword-secret | ||
+ | |||
+ | pgadmin: | ||
+ | image: dpage/pgadmin4 | ||
+ | ports: | ||
+ | - "30001:80" | ||
+ | environment: | ||
+ | PGADMIN_DEFAULT_EMAIL: test | ||
+ | PGADMIN_DEFAULT_PASSWORD: test | ||
+ | logging: | ||
+ | driver: none | ||
+ | networks: | ||
+ | - library_internal | ||
+ | |||
+ | volumes: | ||
+ | workshop-library: | ||
- | # Se adauga la o retea externa | ||
networks: | networks: | ||
- | frontend: | + | library_internal: |
+ | cluster: | ||
external: true | external: true | ||
- | name: external-frontend | + | name: moby-workshop-cluster |
+ | secrets: | ||
+ | workshop-library-pguser-secret: | ||
+ | file: ./secrets/pguser_secret.txt | ||
+ | workshop-library-pgpassword-secret: | ||
+ | file: ./secrets/pgpassword_secret.txt | ||
</code> | </code> | ||
+ | |||
+ | |||
+ | ==== Exercitii ==== | ||
+ | - Creati-va monorepo-ul | ||
+ | - Creati-va folderul de Deployment | ||
+ | - Adaugati-va repo-urile ca si submodule in monorepo | ||
+ | - Scrieti-va fisierul docker-compose.yml care sa tina **intreaga configuratie** a serviciilor (si a bazelor de date) | ||
+ | - Rulati intreg clusterul folosind //docker-compose up --build// | ||
+ |