Skip to content

Commit 7c9d216

Browse files
committed
docs: fixing one example module and generating feature and quickstart docs
1 parent e854757 commit 7c9d216

20 files changed

+1782
-268
lines changed

docs/features/authentication.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Docker Authentication
2+
3+
Testcontainers-Python supports various methods of authenticating with Docker registries. This is essential when working with private registries or when you need to pull images that require authentication.
4+
5+
## Basic Authentication
6+
7+
The simplest way to authenticate is using Docker's built-in credential store. Testcontainers-Python will automatically use credentials stored by Docker:
8+
9+
```python
10+
from testcontainers.generic import GenericContainer
11+
12+
# Docker will automatically use stored credentials
13+
container = GenericContainer("private.registry.com/myimage:latest")
14+
```
15+
16+
## Environment Variables
17+
18+
You can provide registry credentials using environment variables:
19+
20+
```bash
21+
# Set registry credentials
22+
export DOCKER_USERNAME=myuser
23+
export DOCKER_PASSWORD=mypassword
24+
export DOCKER_REGISTRY=private.registry.com
25+
```
26+
27+
## Configuration File
28+
29+
You can also configure authentication in the `.testcontainers.properties` file:
30+
31+
```properties
32+
registry.username=myuser
33+
registry.password=mypassword
34+
registry.url=private.registry.com
35+
```
36+
37+
## Programmatic Authentication
38+
39+
For more control, you can provide credentials programmatically:
40+
41+
```python
42+
from testcontainers.core.config import TestcontainersConfiguration
43+
44+
# Configure registry credentials
45+
config = TestcontainersConfiguration()
46+
config.registry_username = "myuser"
47+
config.registry_password = "mypassword"
48+
config.registry_url = "private.registry.com"
49+
50+
# Use the configuration
51+
container = GenericContainer("private.registry.com/myimage:latest")
52+
```
53+
54+
## AWS ECR Authentication
55+
56+
For Amazon Elastic Container Registry (ECR), Testcontainers-Python supports automatic authentication:
57+
58+
```python
59+
from testcontainers.generic import GenericContainer
60+
61+
# ECR authentication is handled automatically
62+
container = GenericContainer("123456789012.dkr.ecr.region.amazonaws.com/myimage:latest")
63+
```
64+
65+
## Google Container Registry (GCR)
66+
67+
For Google Container Registry, you can use Google Cloud credentials:
68+
69+
```python
70+
from testcontainers.generic import GenericContainer
71+
72+
# GCR authentication using Google Cloud credentials
73+
container = GenericContainer("gcr.io/myproject/myimage:latest")
74+
```
75+
76+
## Azure Container Registry (ACR)
77+
78+
For Azure Container Registry, you can use Azure credentials:
79+
80+
```python
81+
from testcontainers.generic import GenericContainer
82+
83+
# ACR authentication using Azure credentials
84+
container = GenericContainer("myregistry.azurecr.io/myimage:latest")
85+
```
86+
87+
## Best Practices
88+
89+
1. Never commit credentials to version control
90+
2. Use environment variables or secure credential stores
91+
3. Rotate credentials regularly
92+
4. Use the least privileged credentials necessary
93+
5. Consider using Docker credential helpers
94+
6. Use registry-specific authentication when available
95+
7. Keep credentials secure and encrypted
96+
8. Use separate credentials for different environments
97+
98+
## Troubleshooting
99+
100+
If you encounter authentication issues:
101+
102+
1. Verify your credentials are correct
103+
2. Check if the registry is accessible
104+
3. Ensure your Docker daemon is running
105+
4. Check Docker's credential store
106+
5. Verify network connectivity
107+
6. Check for any proxy settings
108+
7. Look for any rate limiting
109+
8. Check registry-specific requirements

docs/features/building_images.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# Building Images from Dockerfiles
2+
3+
Testcontainers-Python allows you to build Docker images from Dockerfiles during test execution. This is useful when you need to test custom images or when you want to ensure your Dockerfile builds correctly.
4+
5+
## Basic Image Building
6+
7+
The simplest way to build an image is using the `build_image` function:
8+
9+
```python
10+
from testcontainers.core.container import build_image
11+
12+
# Build an image from a Dockerfile
13+
image = build_image(
14+
path="path/to/dockerfile/directory",
15+
tag="myapp:test"
16+
)
17+
18+
# Use the built image
19+
with GenericContainer(image) as container:
20+
# Your test code here
21+
pass
22+
```
23+
24+
## Building with Options
25+
26+
You can customize the build process with various options:
27+
28+
```python
29+
# Build with specific Dockerfile
30+
image = build_image(
31+
path="path/to/dockerfile/directory",
32+
dockerfile="Dockerfile.test",
33+
tag="myapp:test"
34+
)
35+
36+
# Build with build arguments
37+
image = build_image(
38+
path="path/to/dockerfile/directory",
39+
buildargs={
40+
"VERSION": "1.0.0",
41+
"ENVIRONMENT": "test"
42+
},
43+
tag="myapp:test"
44+
)
45+
46+
# Build with target stage
47+
image = build_image(
48+
path="path/to/dockerfile/directory",
49+
target="test",
50+
tag="myapp:test"
51+
)
52+
```
53+
54+
## Building with Context
55+
56+
You can specify a build context:
57+
58+
```python
59+
# Build with specific context
60+
image = build_image(
61+
path="path/to/dockerfile/directory",
62+
context="path/to/build/context",
63+
tag="myapp:test"
64+
)
65+
```
66+
67+
## Building with Cache
68+
69+
You can control build caching:
70+
71+
```python
72+
# Build without cache
73+
image = build_image(
74+
path="path/to/dockerfile/directory",
75+
nocache=True,
76+
tag="myapp:test"
77+
)
78+
79+
# Build with specific cache from
80+
image = build_image(
81+
path="path/to/dockerfile/directory",
82+
cache_from=["myapp:latest"],
83+
tag="myapp:test"
84+
)
85+
```
86+
87+
## Building with Platform
88+
89+
You can specify the target platform:
90+
91+
```python
92+
# Build for specific platform
93+
image = build_image(
94+
path="path/to/dockerfile/directory",
95+
platform="linux/amd64",
96+
tag="myapp:test"
97+
)
98+
```
99+
100+
## Building with Labels
101+
102+
You can add labels to the built image:
103+
104+
```python
105+
# Build with labels
106+
image = build_image(
107+
path="path/to/dockerfile/directory",
108+
labels={
109+
"test": "true",
110+
"environment": "test"
111+
},
112+
tag="myapp:test"
113+
)
114+
```
115+
116+
## Best Practices
117+
118+
1. Use appropriate tags
119+
2. Clean up built images
120+
3. Use build arguments for configuration
121+
4. Consider build context size
122+
5. Use appropriate build caching
123+
6. Handle build failures
124+
7. Use appropriate platforms
125+
8. Add meaningful labels
126+
127+
## Common Use Cases
128+
129+
### Building Test Images
130+
131+
```python
132+
def test_custom_image():
133+
# Build test image
134+
image = build_image(
135+
path="path/to/dockerfile/directory",
136+
buildargs={"TEST_MODE": "true"},
137+
tag="myapp:test"
138+
)
139+
140+
# Use the test image
141+
with GenericContainer(image) as container:
142+
# Your test code here
143+
pass
144+
```
145+
146+
### Building with Dependencies
147+
148+
```python
149+
def test_with_dependencies():
150+
# Build base image
151+
base_image = build_image(
152+
path="path/to/base/dockerfile/directory",
153+
tag="myapp:base"
154+
)
155+
156+
# Build test image using base
157+
test_image = build_image(
158+
path="path/to/test/dockerfile/directory",
159+
cache_from=[base_image],
160+
tag="myapp:test"
161+
)
162+
```
163+
164+
### Building for Different Environments
165+
166+
```python
167+
def test_different_environments():
168+
# Build for different environments
169+
environments = ["dev", "test", "staging"]
170+
171+
for env in environments:
172+
image = build_image(
173+
path="path/to/dockerfile/directory",
174+
buildargs={"ENVIRONMENT": env},
175+
tag=f"myapp:{env}"
176+
)
177+
```
178+
179+
## Troubleshooting
180+
181+
If you encounter issues with image building:
182+
183+
1. Check Dockerfile syntax
184+
2. Verify build context
185+
3. Check for missing files
186+
4. Verify build arguments
187+
5. Check for platform compatibility
188+
6. Verify cache settings
189+
7. Check for resource limits
190+
8. Verify Docker daemon state

0 commit comments

Comments
 (0)