Skip to content

Commit 8b2248c

Browse files
committed
✨ add docker, TLS, and OCSP zettelkasten notes
1 parent 7492260 commit 8b2248c

17 files changed

Lines changed: 1062 additions & 2 deletions
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
🗓️ 03042026 2100
2+
3+
# container_registries
4+
5+
**What it is:**
6+
- Services that store, distribute, and manage [[docker_image]] containers
7+
- The "Git repo" equivalent for container images — push to share, pull to deploy
8+
- Standardized by the [[oci_spec]] Distribution Specification
9+
10+
**Problem it solves:**
11+
- Need a central place to push images from CI and pull onto production servers
12+
- Multi-client setups need organized image management with access control
13+
- Without a registry strategy: images live only on build machines, no audit trail, no scanning
14+
15+
## Registry Types
16+
17+
### Public (Docker Hub)
18+
- Default registry, largest image library
19+
- Free for public images
20+
- Rate-limited: 100 pulls/6h anonymous, 200 pulls/6h authenticated
21+
22+
### Cloud-hosted (ECR, GCR, ACR, etc.)
23+
- Managed by cloud provider, integrated with their IAM and CI/CD
24+
- Per-repo access control, vulnerability scanning, geo-replication
25+
- Trade-off: convenience and integration vs. cloud lock-in
26+
27+
### Self-hosted (Harbor, GitLab Registry)
28+
- Full control over access, storage, policies
29+
- Required when compliance mandates data stays on-premise
30+
- Operational burden: you manage uptime, backups, security patches
31+
32+
## Tagging Strategies
33+
34+
### Semantic versioning (`v1.2.3`)
35+
- Clear release tracking, easy rollback to known version
36+
- Best for production deployments
37+
38+
### Git SHA (`abc123f`)
39+
- Ties image directly to source code commit
40+
- Best for CI/CD pipelines and debugging
41+
42+
### `latest` tag
43+
- Mutable — points to different image over time
44+
- Never use in production; acceptable for local development only
45+
46+
Pattern: Tag with both semver and git SHA. Use semver for human communication, SHA for traceability.
47+
48+
## Multi-Client Access Control
49+
50+
For deploying different client stacks from one server:
51+
- Organize repos by client: `registry.example.com/client-a/app`, `registry.example.com/client-b/app`
52+
- Per-repo pull credentials — each client stack only has access to its own images
53+
- Audit logs track who pulled what and when
54+
- Vulnerability scanning ensures no client gets deployed with known CVEs
55+
56+
## When to Use What
57+
58+
### Starting out / single server
59+
- Docker Hub (authenticated) or cloud registry with free tier
60+
- Simple, minimal setup
61+
62+
### Multi-client production
63+
- Private registry (cloud-hosted or self-hosted) with per-client repos
64+
- Access control and scanning are non-negotiable
65+
66+
### Compliance-heavy environments
67+
- Self-hosted (Harbor) for full data sovereignty
68+
- Air-gapped registries for restricted networks
69+
70+
```ad-danger
71+
**Public registries expose images to everyone**: Never push images containing client data, proprietary code, or secrets to public repos. Even "unlisted" doesn't mean secure.
72+
```
73+
74+
```ad-warning
75+
**Docker Hub rate limits**: Anonymous pulls limited to 100/6h. Production deployments should use authenticated pulls or a private registry to avoid deployment failures from rate limiting.
76+
```
77+
78+
---
79+
80+
## References
81+
82+
- https://docs.docker.com/docker-hub/
83+
- https://distribution.github.io/distribution/
84+
- https://goharbor.io/
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
🗓️ 03042026 2100
2+
3+
# docker_buildx
4+
5+
**What it is:**
6+
- Docker CLI plugin for extended build capabilities, powered by **BuildKit** engine
7+
- Replaces the legacy builder with parallel execution, better caching, and multi-platform support
8+
9+
**Problem it solves:**
10+
- Default builder is sequential, slow, and lacks advanced caching
11+
- Building for multiple architectures (amd64 + arm64) requires separate machines or manual emulation
12+
- Passing secrets during build (e.g., private repo credentials) means baking them into image layers
13+
14+
## BuildKit Improvements Over Legacy Builder
15+
16+
### Parallel stage execution
17+
- [[docker_multistage_build]] stages that don't depend on each other build concurrently
18+
- Significant speedup for complex multi-stage builds
19+
20+
### Better layer caching
21+
- Cache-mount for package managers: reuse downloaded packages across builds
22+
- Cache isn't invalidated as aggressively as legacy builder
23+
24+
### Build secrets
25+
- `--secret` flag mounts secrets during build without persisting in [[docker_image]] layers
26+
- Safer than build args (`ARG`) which are visible in image history
27+
- Use for private registry auth, API keys needed during build
28+
29+
### SSH forwarding
30+
- Mount SSH agent during build for private repo cloning
31+
- No SSH keys copied into image layers
32+
33+
## Multi-Platform Builds
34+
35+
Build for multiple architectures in a single command:
36+
- `--platform linux/amd64,linux/arm64` builds both
37+
- Uses QEMU emulation or cross-compilation
38+
- Push multi-arch manifest to [[container_registries]] — correct image pulled automatically based on host architecture
39+
- Relevant if deploying to mixed server types or ARM-based cloud instances
40+
41+
## Cache Backends
42+
43+
### Local cache
44+
- Default, stored on build machine
45+
- Fast but not shared across CI runners
46+
47+
### Registry cache (`--cache-to type=registry`)
48+
- Push cache layers to registry, pull on next build
49+
- Shared across CI runners and developers
50+
- Trade-off: extra registry storage and pull time
51+
52+
### GitHub Actions cache
53+
- Built-in integration for GitHub CI
54+
- Free within GitHub Actions storage limits
55+
56+
## When to Use
57+
58+
Use for:
59+
- CI/CD pipelines (parallel builds, shared caching)
60+
- Multi-architecture deployments
61+
- Builds needing private repo access (SSH, secrets)
62+
- Any project where build time matters
63+
64+
Skip for:
65+
- Simple single-platform builds where the default builder is fast enough
66+
- Local development where build speed isn't a bottleneck
67+
68+
## Enabling BuildKit
69+
70+
- Docker Desktop: enabled by default
71+
- Linux servers: set `DOCKER_BUILDKIT=1` or configure in `/etc/docker/daemon.json`
72+
- Docker Engine 23.0+: BuildKit is the default builder
73+
74+
See [[dockerfile_best_practices]] for writing Dockerfiles that maximize BuildKit's cache efficiency.
75+
76+
```ad-warning
77+
**BuildKit may need explicit enabling on Linux servers**: Docker Desktop includes it by default, but production Linux hosts running older Docker versions need `DOCKER_BUILDKIT=1` or daemon config. Verify before assuming cache features work.
78+
```
79+
80+
```ad-example
81+
**Build secrets**: Mount a database password during build for a migration step — `docker buildx build --secret id=db_pass,src=./secret.txt .` — the secret is available during build but never appears in any image layer.
82+
```
83+
84+
---
85+
86+
## References
87+
88+
- https://docs.docker.com/build/buildkit/
89+
- https://docs.docker.com/build/building/multi-platform/
90+
- https://docs.docker.com/build/cache/

www/docs/zettelkasten/infrastructure/docker/docker_compose.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ A `docker-compose.yml` defines:
1919
### Services
2020
- Containers to run
2121
- Each service specifies image/build context, ports, environment variables, dependencies, health checks
22+
- For selectively running subsets, see [[docker_compose_profiles]]
23+
- For reusing service definitions across clients, see [[docker_compose_extends]]
2224

2325
### Networks
2426
- How containers communicate
@@ -45,6 +47,7 @@ Skip for:
4547
- Only waits for containers to start, NOT for services to be ready
4648
- Combine with `condition: service_healthy` to wait for [[docker_healthcheck]] to pass
4749
- Without health checks, app might try connecting to database that's still initializing
50+
- For advanced dependency strategies including init containers, see [[docker_compose_dependencies]]
4851

4952
## Environment Variables and Config
5053

@@ -54,7 +57,7 @@ Configuration options:
5457
- Substitute from host environment
5558
- Mount config files via volumes
5659

57-
Pattern: Use environment variables for secrets and runtime config, mount files for complex configuration.
60+
Pattern: Use environment variables for secrets and runtime config, mount files for complex configuration. For detailed patterns, see [[docker_env_management]].
5861

5962
## Compose vs Orchestration
6063

@@ -76,6 +79,8 @@ For production needing auto-scaling, rolling updates, self-healing: use orchestr
7679
**Using Compose for production scale**: Compose has no auto-scaling, no rolling updates, no multi-host support. Great for single-host deployments but not designed for production scale. Use [[docker_orchestration]] platforms instead.
7780
```
7881

82+
For resource constraints per service, see [[docker_resource_limits]]. For log management, see [[docker_logging]].
83+
7984
---
8085

8186
## References
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
🗓️ 03042026 2100
2+
3+
# docker_compose_dependencies
4+
5+
**What it is:**
6+
- Strategies beyond basic `depends_on` to manage service startup order and readiness in [[docker_compose]]
7+
- Uses health checks and completion conditions to ensure services are truly ready before dependents start
8+
9+
**Problem it solves:**
10+
- Basic `depends_on` only waits for container start, not readiness
11+
- Database container "started" but still initializing — app connects and crashes
12+
- In multi-client stacks, a shared database must be fully ready before any client service connects
13+
14+
## Condition Options
15+
16+
### `service_started` (default)
17+
- Waits for container to start, nothing more
18+
- Sufficient when the dependency starts fast or the app handles retries
19+
20+
### `service_healthy`
21+
- Waits for [[docker_healthcheck]] to pass
22+
- The correct choice for databases, caches, message brokers — anything with initialization time
23+
- Requires a `healthcheck` defined on the dependency service
24+
25+
### `service_completed_successfully`
26+
- Waits for a one-shot container to exit with code 0
27+
- Perfect for init/migration containers that must finish before the app starts
28+
- If the init container fails (non-zero exit), dependent services won't start
29+
30+
## Init Container Pattern
31+
32+
Run setup tasks before the main application:
33+
- Database migration container runs and exits
34+
- Schema seeding or data loading completes
35+
- App service has `depends_on` with `condition: service_completed_successfully`
36+
- Guarantees migrations are applied before any client traffic hits the app
37+
38+
## Restart Policies
39+
40+
What happens when a dependency crashes after startup:
41+
- `restart: unless-stopped` — restarts on crash, stays stopped if manually stopped
42+
- `restart: on-failure` — restarts only on non-zero exit codes
43+
- `restart: always` — restarts no matter what, including after host reboot
44+
- Choose based on whether the service should self-heal or require manual intervention
45+
46+
## When to Skip depends_on
47+
48+
Sometimes application-level resilience is better:
49+
- App has connection retry logic with backoff — more resilient than strict ordering
50+
- Microservices that gracefully degrade when a dependency is down
51+
- `depends_on` only helps at startup; it doesn't restart your app if the dependency crashes later
52+
53+
## Transitive Dependencies
54+
55+
A depends on B depends on C:
56+
- Compose resolves the chain transitively — C starts first, then B, then A
57+
- But startup time compounds: if C takes 30s and B takes 20s, A waits 50s+
58+
- Keep dependency chains shallow where possible
59+
60+
```ad-warning
61+
**`service_completed_successfully` kills dependents on failure**: If the init container exits non-zero, dependent services never start. Always handle errors in init scripts and provide clear exit codes.
62+
```
63+
64+
```ad-example
65+
**Migration container pattern**: DB starts → migration container runs `flyway migrate` and exits → app starts only after migration succeeds. This guarantees schema consistency across all client stacks.
66+
```
67+
68+
---
69+
70+
## References
71+
72+
- https://docs.docker.com/compose/startup-order/
73+
- https://docs.docker.com/compose/compose-file/05-services/#depends_on
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
🗓️ 03042026 2100
2+
3+
# docker_compose_extends
4+
5+
**What it is:**
6+
- Mechanisms to reuse and override Compose configuration without copy-pasting
7+
- Three approaches: `extends` keyword, YAML anchors (`&`/`*`/`<<`), and `x-` extension fragments
8+
9+
**Problem it solves:**
10+
- Multi-client setups duplicate service definitions across files
11+
- Copy-pasting configs leads to drift — change one, forget the others
12+
- Need a way to define a base service once and override per client or environment
13+
14+
## extends Keyword
15+
16+
Pulls base service config from another file or same file, then overrides specific fields:
17+
- `extends.file` + `extends.service` references a base definition
18+
- Overriding file adds or replaces fields on top of base
19+
- Good for per-client overrides: `base.yml` defines the service, `client-a.yml` extends and customizes
20+
21+
### Limitations
22+
- Cannot extend services that use `depends_on` with `condition` — restructure dependencies in the extending file
23+
- Lists (like `ports`, `volumes`) are appended, not replaced — can lead to duplicates
24+
- Single inheritance only — no chaining extends through multiple levels
25+
26+
## YAML Anchors and Aliases
27+
28+
DRY within a single file using native YAML:
29+
- `&anchor` defines a reusable block
30+
- `*anchor` references it
31+
- `<<: *anchor` merges the block into current mapping
32+
33+
### When to prefer anchors
34+
- Repetitive config within one file (same [[docker_logging]] config, same resource limits for all services)
35+
- Simpler than extends for same-file reuse
36+
37+
## x- Extension Fragments
38+
39+
Compose ignores top-level keys starting with `x-`:
40+
- Define reusable blocks as `x-common-env`, `x-logging`, etc.
41+
- Reference with YAML anchors
42+
- Cleaner than anchors buried inside service definitions
43+
- Compose v2+ feature
44+
45+
## When to Use What
46+
47+
### extends
48+
- Cross-file reuse (base.yml + per-client overrides)
49+
- Environment-specific configs (dev.yml extends base.yml)
50+
51+
### Anchors / x- fragments
52+
- Same-file repetition (shared logging, labels, deploy config)
53+
- Quick DRY without extra files
54+
55+
### Separate compose files
56+
- When clients need fully isolated namespaces and you combine with [[docker_compose_profiles]] isn't sufficient
57+
- `docker compose -f base.yml -f client-a.yml up`
58+
59+
## Trade-offs
60+
61+
### extends
62+
- Compose-aware, readable, explicit inheritance
63+
- Limited: no list merging control, no multi-level chaining
64+
65+
### YAML anchors
66+
- Flexible, works at YAML level
67+
- Harder to debug — resolved before Compose processes the file, mistakes produce silent wrong config
68+
69+
```ad-warning
70+
**extends + depends_on condition**: `extends` cannot extend services using `depends_on` with `condition: service_healthy`. Move dependency declarations to the extending file instead.
71+
```
72+
73+
```ad-danger
74+
**Silent anchor failures**: YAML anchors are resolved before Compose validates the file. A typo in an anchor name or wrong merge produces incorrect config with no Compose-level error — only runtime surprises.
75+
```
76+
77+
---
78+
79+
## References
80+
81+
- https://docs.docker.com/compose/extends/
82+
- https://docs.docker.com/compose/compose-file/11-extension/

0 commit comments

Comments
 (0)