-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Improve Docker Compose docs #9461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eddumelendez
merged 9 commits into
testcontainers:main
from
etrandafir93:docs_restructure_docker_compose
Nov 26, 2024
+140
−113
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7938cc2
updated docker compose redme
etrandafir93 39c56a4
formatting
etrandafir93 048a594
fix checkstyle rule
etrandafir93 d0f360e
reuse existing tests wherever possible
etrandafir93 deec12d
minor fixes
etrandafir93 2572742
use sembr, remove javadoc links, minor changes
etrandafir93 2037dfa
Apply suggestions from code review
eddumelendez e4bc2a4
Update docs/modules/docker_compose.md
eddumelendez 9f78359
Merge branch 'main' into docs_restructure_docker_compose
eddumelendez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
core/src/test/java/org/testcontainers/junit/ComposeContainerWithWaitStrategies.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package org.testcontainers.junit; | ||
|
|
||
| import org.junit.Test; | ||
| import org.testcontainers.containers.ComposeContainer; | ||
| import org.testcontainers.containers.wait.strategy.Wait; | ||
|
|
||
| import java.io.File; | ||
| import java.time.Duration; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class ComposeContainerWithWaitStrategies { | ||
|
|
||
| private static final int REDIS_PORT = 6379; | ||
|
|
||
| @Test | ||
| public void testComposeContainerConstructor() { | ||
| try ( | ||
| // composeContainerWithCombinedWaitStrategies { | ||
| ComposeContainer compose = new ComposeContainer(new File("src/test/resources/composev2/compose-test.yml")) | ||
| .withExposedService("redis-1", REDIS_PORT, Wait.forSuccessfulCommand("redis-cli ping")) | ||
| .withExposedService("db-1", 3306, Wait.forLogMessage(".*ready for connections.*\\n", 1)) | ||
| // } | ||
| ) { | ||
| compose.start(); | ||
| containsStartedServices(compose, "redis-1", "db-1"); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testComposeContainerWaitForPortWithTimeout() { | ||
| try ( | ||
| // composeContainerWaitForPortWithTimeout { | ||
| ComposeContainer compose = new ComposeContainer(new File("src/test/resources/composev2/compose-test.yml")) | ||
| .withExposedService( | ||
| "redis-1", | ||
| REDIS_PORT, | ||
| Wait.forListeningPort().withStartupTimeout(Duration.ofSeconds(30)) | ||
| ) | ||
| // } | ||
| ) { | ||
| compose.start(); | ||
| containsStartedServices(compose, "redis-1"); | ||
| } | ||
| } | ||
|
|
||
| private void containsStartedServices(ComposeContainer compose, String... expectedServices) { | ||
| for (String serviceName : expectedServices) { | ||
| assertThat(compose.getContainerByServiceName(serviceName)) | ||
| .as("Container should be found by service name %s", serviceName) | ||
| .isPresent(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,158 +2,110 @@ | |||||
|
|
||||||
| ## Benefits | ||||||
|
|
||||||
| Similar to generic containers support, it's also possible to run a bespoke set of services | ||||||
| specified in a `docker-compose.yml` file. | ||||||
| Similar to generic container support, it's also possible to run a bespoke set of services specified in a `docker-compose.yml` file. | ||||||
|
|
||||||
| This is intended to be useful on projects where Docker Compose is already used in dev or other environments to define | ||||||
| services that an application may be dependent upon. | ||||||
| This is especially useful for projects where Docker Compose is already used in development or other environments to define services that an application may be dependent upon. | ||||||
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| Behind the scenes, Testcontainers actually launches a temporary Docker Compose client - in a container, of course, so | ||||||
| it's not necessary to have it installed on all developer/test machines. | ||||||
| The [`ComposeContainer`](http://static.javadoc.io/org.testcontainers/testcontainers/{{ latest_version }}/org/testcontainers/containers/ComposeContainer.html) leverages [Compose V2](https://www.docker.com/blog/announcing-compose-v2-general-availability/), making it easy to use the same dependencies from the development environment within tests. | ||||||
|
||||||
| The [`ComposeContainer`](http://static.javadoc.io/org.testcontainers/testcontainers/{{ latest_version }}/org/testcontainers/containers/ComposeContainer.html) leverages [Compose V2](https://www.docker.com/blog/announcing-compose-v2-general-availability/), making it easy to use the same dependencies from the development environment within tests. | |
| The `ComposeContainer` leverages [Compose V2](https://www.docker.com/blog/announcing-compose-v2-general-availability/), making it easy to use the same dependencies from the development environment within tests. |
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
eddumelendez marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.