-
-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create networks with random names (#1993)
* chore: handle error in test * feat: add a first-order package for creating networks * fix: do not print out network name, as it's random * docs: mention since version * chore: use smaller images in test * chore: move WithNetwork option to the network package Because it was introduced in the current release, it's fine to change the signature * fix: proper return on error * fix: more proper returns * chore: do not default attachable networks It relates to Docker Swarm * feat: separate concerns regarding new networks and reusable ones * chore: pass context when creating the new network * chore: support multiple aliases
- Loading branch information
1 parent
9c97abf
commit 2120c33
Showing
18 changed files
with
799 additions
and
520 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
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.