44
55Create and start a Docker Compose environment:
66
7- ``` javascript
7+ ``` js
88const { DockerComposeEnvironment } = require (" testcontainers" );
99
1010const composeFilePath = " /path/to/build-context" ;
@@ -15,7 +15,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
1515
1616You can override by providing [ multiple compose files] ( https://docs.docker.com/compose/extends/#multiple-compose-files ) :
1717
18- ``` javascript
18+ ``` js
1919const environment = await new DockerComposeEnvironment (
2020 composeFilePath,
2121 [
@@ -27,14 +27,14 @@ const environment = await new DockerComposeEnvironment(
2727
2828Provide a list of service names to only start those services:
2929
30- ``` javascript
30+ ``` js
3131const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
3232 .up ([" redis-1" , " postgres-1" ]);
3333```
3434
3535### With wait strategy
3636
37- ``` javascript
37+ ``` js
3838const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
3939 .withWaitStrategy (" redis-1" , Wait .forLogMessage (" Ready to accept connections" ))
4040 .withWaitStrategy (" postgres-1" , Wait .forHealthCheck ())
@@ -46,7 +46,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
4646By default Testcontainers uses the "listening ports" wait strategy for all containers. If you'd like to override
4747the default wait strategy for all services, you can do so:
4848
49- ``` javascript
49+ ``` js
5050const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
5151 .withDefaultWaitStrategy (Wait .forHealthCheck ())
5252 .up ();
@@ -56,7 +56,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
5656
5757Testcontainers will automatically pull an image if it doesn't exist. This is configurable:
5858
59- ``` javascript
59+ ``` js
6060const { DockerComposeEnvironment , PullPolicy } = require (" testcontainers" );
6161
6262const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
@@ -66,7 +66,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
6666
6767Create a custom pull policy:
6868
69- ``` typescript
69+ ``` ts
7070const { GenericContainer, ImagePullPolicy } = require (" testcontainers" );
7171
7272class CustomPullPolicy implements ImagePullPolicy {
@@ -82,7 +82,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
8282
8383### With rebuild
8484
85- ``` javascript
85+ ``` js
8686const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
8787 .withBuild ()
8888 .up ();
@@ -92,7 +92,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
9292
9393See [ environment file] ( https://docs.docker.com/compose/environment-variables/#using-the---env-file--option ) .
9494
95- ``` javascript
95+ ``` js
9696const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
9797 .withEnvironmentFile (" .env.custom" )
9898 .up ();
@@ -102,15 +102,15 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
102102
103103See [ profiles] ( https://docs.docker.com/compose/profiles/ ) .
104104
105- ``` javascript
105+ ``` js
106106const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
107107 .withProfiles (" profile1" , " profile2" )
108108 .up ();
109109```
110110
111111### With no recreate
112112
113- ``` javascript
113+ ``` js
114114const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
115115 .withNoRecreate ()
116116 .up ();
@@ -126,7 +126,7 @@ services:
126126 image : redis:${TAG}
127127` ` `
128128
129- ` ` ` javascript
129+ ` ` ` js
130130const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
131131 .withEnvironment({ "TAG" : " VALUE" })
132132 .up();
@@ -136,7 +136,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
136136
137137See [ project name] ( https://docs.docker.com/compose/project-name/ ) .
138138
139- ``` javascript
139+ ``` js
140140const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
141141 .withProjectName (" test" )
142142 .up ();
@@ -146,7 +146,7 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
146146
147147See [ docker-compose] ( https://github.com/PDMLab/docker-compose/ ) library.
148148
149- ``` javascript
149+ ``` js
150150const environment = await new DockerComposeEnvironment (composeFilePath, composeFile)
151151 .withClientOptions ({ executable: { standalone: true , executablePath: " /path/to/docker-compose" } })
152152 .up ();
@@ -157,21 +157,21 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
157157
158158Testcontainers 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.
159159
160- ``` javascript
160+ ``` js
161161const environment = await new DockerComposeEnvironment (composeFilePath, composeFile).up ();
162162await environment .down ();
163163```
164164
165165If you need to wait for the environment to be downed, you can provide a timeout:
166166
167- ``` javascript
167+ ``` js
168168const environment = await new DockerComposeEnvironment (composeFilePath, composeFile).up ();
169169await environment .down ({ timeout: 10_000 }); // 10 seconds
170170```
171171
172172Volumes created by the environment are removed when stopped. This is configurable:
173173
174- ``` javascript
174+ ``` js
175175const environment = await new DockerComposeEnvironment (composeFilePath, composeFile).up ();
176176await environment .down ({ removeVolumes: false });
177177```
@@ -180,7 +180,7 @@ await environment.down({ removeVolumes: false });
180180
181181If you have multiple docker-compose environments which share dependencies such as networks, you can stop the environment instead of downing it:
182182
183- ``` javascript
183+ ``` js
184184const environment = await new DockerComposeEnvironment (composeFilePath, composeFile).up ();
185185await environment .stop ();
186186```
@@ -189,6 +189,6 @@ await environment.stop();
189189
190190Interact 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.
191191
192- ``` javascript
192+ ``` js
193193const container = environment .getContainer (" alpine-1" );
194194```
0 commit comments