4
4
5
5
Create and start a Docker Compose environment:
6
6
7
- ``` javascript
7
+ ``` js
8
8
const { DockerComposeEnvironment } = require (" testcontainers" );
9
9
10
10
const composeFilePath = " /path/to/build-context" ;
@@ -15,7 +15,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
15
15
16
16
You can override by providing [ multiple compose files] ( https://docs.docker.com/compose/extends/#multiple-compose-files ) :
17
17
18
- ``` javascript
18
+ ``` js
19
19
const environment = await new DockerComposeEnvironment (
20
20
composeFilePath,
21
21
[
@@ -27,14 +27,14 @@ const environment = await new DockerComposeEnvironment(
27
27
28
28
Provide a list of service names to only start those services:
29
29
30
- ``` javascript
30
+ ``` js
31
31
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
32
32
.up ([" redis-1" , " postgres-1" ]);
33
33
```
34
34
35
35
### With wait strategy
36
36
37
- ``` javascript
37
+ ``` js
38
38
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
39
39
.withWaitStrategy (" redis-1" , Wait .forLogMessage (" Ready to accept connections" ))
40
40
.withWaitStrategy (" postgres-1" , Wait .forHealthCheck ())
@@ -46,7 +46,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
46
46
By default Testcontainers uses the "listening ports" wait strategy for all containers. If you'd like to override
47
47
the default wait strategy for all services, you can do so:
48
48
49
- ``` javascript
49
+ ``` js
50
50
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
51
51
.withDefaultWaitStrategy (Wait .forHealthCheck ())
52
52
.up ();
@@ -56,7 +56,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
56
56
57
57
Testcontainers will automatically pull an image if it doesn't exist. This is configurable:
58
58
59
- ``` javascript
59
+ ``` js
60
60
const { DockerComposeEnvironment , PullPolicy } = require (" testcontainers" );
61
61
62
62
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
@@ -66,7 +66,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
66
66
67
67
Create a custom pull policy:
68
68
69
- ``` typescript
69
+ ``` ts
70
70
const { GenericContainer, ImagePullPolicy } = require (" testcontainers" );
71
71
72
72
class CustomPullPolicy implements ImagePullPolicy {
@@ -82,7 +82,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
82
82
83
83
### With rebuild
84
84
85
- ``` javascript
85
+ ``` js
86
86
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
87
87
.withBuild ()
88
88
.up ();
@@ -92,7 +92,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
92
92
93
93
See [ environment file] ( https://docs.docker.com/compose/environment-variables/#using-the---env-file--option ) .
94
94
95
- ``` javascript
95
+ ``` js
96
96
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
97
97
.withEnvironmentFile (" .env.custom" )
98
98
.up ();
@@ -102,15 +102,15 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
102
102
103
103
See [ profiles] ( https://docs.docker.com/compose/profiles/ ) .
104
104
105
- ``` javascript
105
+ ``` js
106
106
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
107
107
.withProfiles (" profile1" , " profile2" )
108
108
.up ();
109
109
```
110
110
111
111
### With no recreate
112
112
113
- ``` javascript
113
+ ``` js
114
114
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
115
115
.withNoRecreate ()
116
116
.up ();
@@ -126,7 +126,7 @@ services:
126
126
image : redis:${TAG}
127
127
` ` `
128
128
129
- ` ` ` javascript
129
+ ` ` ` js
130
130
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
131
131
.withEnvironment({ "TAG" : " VALUE" })
132
132
.up();
@@ -136,7 +136,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
136
136
137
137
See [ project name] ( https://docs.docker.com/compose/project-name/ ) .
138
138
139
- ``` javascript
139
+ ``` js
140
140
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
141
141
.withProjectName (" test" )
142
142
.up ();
@@ -146,7 +146,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
146
146
147
147
See [ docker-compose] ( https://github.com/PDMLab/docker-compose/ ) library.
148
148
149
- ``` javascript
149
+ ``` js
150
150
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
151
151
.withClientOptions ({ executable: { standalone: true , executablePath: " /path/to/docker-compose" } })
152
152
.up ();
@@ -157,21 +157,21 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
157
157
158
158
Testcontainers by default will not wait until the environment has downed. It will simply issue the down command and return immediately. This is to save time when running tests.
159
159
160
- ``` javascript
160
+ ``` js
161
161
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile).up ();
162
162
await environment .down ();
163
163
```
164
164
165
165
If you need to wait for the environment to be downed, you can provide a timeout:
166
166
167
- ``` javascript
167
+ ``` js
168
168
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile).up ();
169
169
await environment .down ({ timeout: 10_000 }); // 10 seconds
170
170
```
171
171
172
172
Volumes created by the environment are removed when stopped. This is configurable:
173
173
174
- ``` javascript
174
+ ``` js
175
175
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile).up ();
176
176
await environment .down ({ removeVolumes: false });
177
177
```
@@ -180,7 +180,7 @@ await environment.down({ removeVolumes: false });
180
180
181
181
If you have multiple docker-compose environments which share dependencies such as networks, you can stop the environment instead of downing it:
182
182
183
- ``` javascript
183
+ ``` js
184
184
const environment = await new DockerComposeEnvironment (composeFilePath, composeFile).up ();
185
185
await environment .stop ();
186
186
```
@@ -189,6 +189,6 @@ await environment.stop();
189
189
190
190
Interact with the containers in your compose environment as you would any other Generic Container. Note that the container name suffix has changed from ` _ ` to ` - ` between docker-compose v1 and v2 respectively.
191
191
192
- ``` javascript
192
+ ``` js
193
193
const container = environment .getContainer (" alpine-1" );
194
194
```
0 commit comments