forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into user-defined-lifecycle-hooks
- Loading branch information
Showing
19 changed files
with
834 additions
and
524 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,13 +1,30 @@ | ||
# How to create a network | ||
|
||
Apart from creating containers, `Testcontainers for Go` also allows you to create networks. This is useful when you need to connect multiple containers to the same network. | ||
Apart from creating containers, `Testcontainers for Go` allows you to create networks. This is useful when you need to connect multiple containers to the same network. | ||
|
||
## Usage example | ||
- Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
||
<!--codeinclude--> | ||
[Creating a network](../../network_test.go) inside_block:createNetwork | ||
<!--/codeinclude--> | ||
For that, please import the `testcontainers/network` package. | ||
|
||
```go | ||
import "github.com/testcontainers/testcontainers-go/network" | ||
``` | ||
|
||
Then, you can create a network using the `network.New` function. This function receives a variadic list of options that can be used to configure the network. | ||
|
||
- `WithAttachable()` | ||
- `WithCheckDuplicate()` | ||
- `WithDriver(driver string)` | ||
- `WithEnableIPv6()` | ||
- `WithInternal()` | ||
- `WithLabels(labels map[string]string)` | ||
- `WithIPAMConfig(config *network.IPAMConfig)` | ||
|
||
It's important to mention that the name of the network is automatically generated by the library, and it's not possible to set it manually. However, you can retrieve the name of the network using the `Name` field of the `DockerNetwork` struct returned by the `New` function. | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating a network with IPAM](../../network_test.go) inside_block:withIPAM | ||
<!--/codeinclude--> | ||
[Creating a network](../../network/network_test.go) inside_block:createNetwork | ||
[Creating a network with options](../../network/network_test.go) inside_block:newNetworkWithOptions | ||
<!--/codeinclude--> |
This file contains 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 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
Oops, something went wrong.