You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/features/creating_container.md
+8-11Lines changed: 8 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# How to create a container
1
+
# How to Create a Container
2
2
3
3
Testcontainers-Python is a thin wrapper around Docker designed for use in tests. Anything you can run in Docker, you can spin up with Testcontainers-Python:
4
4
@@ -29,14 +29,14 @@ def test_basic_container():
29
29
30
30
## Advanced Container Configuration
31
31
32
-
For more complex scenarios, you can use the `run` helper function which provides a high-level interface similar to Docker's `docker run`command. This helper automatically handles:
32
+
For more complex scenarios, use the `run` helper function. This high-level interface is similar to `docker run`and automatically handles:
33
33
34
34
- Creating temporary networks
35
35
- Mounting files or tmpfs
36
36
- Waiting for container readiness
37
37
- Container cleanup
38
38
39
-
Here's an example showing various configuration options:
39
+
Example with various configuration options:
40
40
41
41
```python
42
42
import io
@@ -85,18 +85,16 @@ def test_nginx_advanced():
85
85
86
86
## Container Lifecycle Management
87
87
88
-
Testcontainers-Python provides several ways to manage container lifecycle:
89
-
90
-
1. Using context manager (recommended):
88
+
Testcontainers-Python offers several ways to manage container lifecycle:
91
89
90
+
1.**Context manager (recommended):**
92
91
```python
93
92
with GenericContainer("nginx:alpine") as container:
94
93
# Container is automatically started and stopped
95
94
pass
96
95
```
97
96
98
-
2. Manual management:
99
-
97
+
2.**Manual management:**
100
98
```python
101
99
container = GenericContainer("nginx:alpine")
102
100
container.start()
@@ -108,8 +106,7 @@ finally:
108
106
container.remove()
109
107
```
110
108
111
-
3. Using pytest fixtures:
112
-
109
+
3.**Pytest fixtures:**
113
110
```python
114
111
import pytest
115
112
from testcontainers.generic import GenericContainer
0 commit comments