For running multi-container applications.
Only for backward compatibility.
Project name The value is set also as COMPOSE_PROJECT_NAME for further use.
Map where the keys are the service names.
services:
web:
...
db:
...
The image to start the container from.
A custom container name.
Override the container default command (CMD).
Port mapping between the machone and the container. Allows external access to the service from outside the container. (HOST:CONTAINER).
Mounts host paths (or named volumes) that are accessible by the service container. (HOST VOLUME:CONTAINER PATH).
The policy on container termination.
always: always restart the container until it is removed.
Defines environment variables set in the container.
Metadata for the container.
- "key=value"
e.g.
- "traefik.enable=true"
Declares a check that's run to determine whether the container is healthy.
Controls the order of service startup (and shutdown). Useful if services are closely coupled.
Persistent data store (named volumes) that can be used by a service.
HTTP Reverse Proxy for integrating components (services). A reverse proxy is a server, app, or cloud service that sits in front of one or more services to intercept and inspect incoming client requests before forwarding them to the service and subsequently returning the service's response to the client.
Traefik Dashboard: http://localhost:8080
Traefik inspects the services to set-up the right configuration.
Object-Relational Database Management System (ORDBMS). Database Server;
postgres
- POSTGRES_PASSWORD (required) sets the superuser (defined by POSTGRES_USER) password.
- POSTGRES_USER (optional, default: postgres) becomes the superuser.
- POSTGRES_DB (optional, default: postgres) the name of the default database.
- POSTGRES_HOST_AUTH_METHOD (optional) controls auth-method for all databases and all users.
- trust: allow the connection unconditionally. Allows anyone that can connect to log in without need of password. PostgreSQL assumes that anyone who can connect to the server is authorized to access the database with whatever database user name they specify.
- password: the client must provide an unencrypted password for authentication.
A named volume to /var/lib/postgresql/data
postgres:
volumes:
- postgres:/var/lib/postgresql/data
volumes:
postgres:
Postgres works on port 5432.
healthcheck: test: ["CMD-SHELL", "pg_isready", "-d", "db_prod"] // Command pg_isready -d db_prod -> specifies the name of the database to connect to interval: 10s // The interval between the health checks (in seconds) timeout: 5s // The maximum number of seconds to wait when attempting connection before returning that the server is not responding retries: 5 // THe max number of retries before giving up. start_period: 30s // Provides initialization time for containers that need time to bootstrap.
depends_on:
postgres:
condition: service_healthy
(when traefik and postgres are in same docker compose file)
labels: // enable traefik on Postgres directly
-
"traefik.enable=true"
// set entrypoint rule to TCP _ (for TCP (or all TLS connections) use HostSNI= Host Server Name Indication)
-
"traefik.tcp.routers.postgres.rule=HostSNI(
_
)"// set routing using TCP
-
"traefik.tcp.routers.postgres.entrypoints=tcp"
// Set routing to postgres
-
"traefik.tcp.routers.postgres.service=postgres"
// Redirect everything traefik receives on port 5432 to Postgres at port 5432
-
"traefik.tcp.services.postgres.loadbalancer.server.port=5432"
Database Schema Change Management solution.
Tut-O-Pedia backend API based on SpringBoot - Rest
Tut-O-Pedia frontend application based on React.