-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathdocker-compose-standards.mdc
More file actions
106 lines (87 loc) · 2.56 KB
/
Copy pathdocker-compose-standards.mdc
File metadata and controls
106 lines (87 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
---
description: Docker Compose standards Rule
globs:
alwaysApply: false
---
## Rule Details
- **Name:** docker_compose_best_practices
- **Description:** Enforces best practices in docker-compose files to ensure maintainability, security, and consistency
## Filters
- file name: `docker-compose\\.ya?ml$`
- event: `(file_create|file_modify)`
## Rejections
- Conditions:
- pattern `^\\s*version\\s*:` – The 'version' field is deprecated in Docker Compose files. Compose files are now version-less by default.
## Rejections
- Conditions:
- pattern `^( |\t)` – Inconsistent indentation detected. Use 2 spaces for indentation.
## Rejections
- Conditions:
- pattern `^\\s*links\\s*:` – The 'links' key is deprecated. Use networks and service names for inter-service communication.
## Rejections
- Conditions:
- pattern `^\\s*image\\s*:\\s*[^:]+$` – Specify an explicit image tag to ensure consistency.
## Rejections
- Conditions:
- pattern `^\\s*privileged\\s*:\\s*true` – Running services in privileged mode is discouraged for security reasons.
## Rejections
- Conditions:
- pattern `^\\s*services\\s*:\\s*[^\\n]+\\n(?!.*\\blimits\\b)` – Define resource limits for each service to prevent resource exhaustion.
## Suggestions
- Guidance:
To adhere to Docker Compose best practices:
1. **Omit the 'version' field**: Compose files are version-less by default.
```yaml
services:
web:
image: nginx
```
2. **Use consistent indentation**: Use 2 spaces for indentation.
```yaml
services:
web:
image: nginx
```
3. **Avoid 'links' key**: Use networks and service names for service communication.
```yaml
services:
web:
image: nginx
networks:
- my-network
db:
image: mysql
networks:
- my-network
networks:
my-network:
```
4. **Specify explicit image tags**: Prevent unintended updates by defining image tags.
```yaml
services:
web:
image: nginx:1.21.0
```
5. **Avoid privileged mode**: Do not use 'privileged: true'. Grant specific capabilities if necessary.
```yaml
services:
web:
image: nginx
cap_add:
- NET_ADMIN
```
6. **Define resource limits**: Prevent services from consuming excessive resources.
```yaml
services:
web:
image: nginx
deploy:
resources:
limits:
cpus: '0.50'
memory: '512M'
```
Implementing these practices ensures secure, maintainable, and consistent Docker Compose configurations.
## Metadata
- Priority: high
- Version: 1.1