Skip to content

Commit 8d4a808

Browse files
committed
docs: Pin image version explicit
1 parent 92af06f commit 8d4a808

19 files changed

+45
-48
lines changed

docs/api/connection_string_provider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The Connection String Provider API provides a standardized way to access and man
1111
Register a custom connection string provider via the container builder:
1212

1313
```csharp
14-
IContainer container = new ContainerBuilder()
14+
IContainer container = new ContainerBuilder("alpine:3.20.0")
1515
.WithConnectionStringProvider(new MyProvider1())
1616
.Build();
1717

docs/api/create_docker_container.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Both `ENTRYPOINT` and `CMD` allows you to configure an executable and parameters
99
Instead of running the NGINX application, the following container configuration overrides the default start procedure of the image and just tests the NGINX configuration file.
1010

1111
```csharp
12-
_ = new ContainerBuilder()
12+
_ = new ContainerBuilder("nginx:1.26.3-alpine3.20")
1313
.WithEntrypoint("nginx")
1414
.WithCommand("-t");
1515
```
@@ -25,7 +25,7 @@ Apps or services running inside a container are usually configured either with e
2525
To configure an ASP.NET Core application, either one or both mechanisms can be used.
2626

2727
```csharp
28-
_ = new ContainerBuilder()
28+
_ = new ContainerBuilder("mcr.microsoft.com/dotnet/aspnet:10.0")
2929
.WithEnvironment("ASPNETCORE_URLS", "https://+")
3030
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Path", "/app/certificate.pfx")
3131
.WithEnvironment("ASPNETCORE_Kestrel__Certificates__Default__Password", "password")
@@ -39,12 +39,12 @@ _ = new ContainerBuilder()
3939
Sometimes it is necessary to copy files into the container to configure the services running inside the container in advance, like the `appsettings.json` or an SSL certificate. The container builder API provides a member `WithResourceMapping(string, string)`, including several overloads to copy directories or individual files to a container's directory.
4040

4141
```csharp title="Copying a directory"
42-
_ = new ContainerBuilder()
42+
_ = new ContainerBuilder("alpine:3.20.0")
4343
.WithResourceMapping(new DirectoryInfo("."), "/app/");
4444
```
4545

4646
```csharp title="Copying a file"
47-
_ = new ContainerBuilder()
47+
_ = new ContainerBuilder("alpine:3.20.0")
4848
// Copy 'appsettings.json' into the '/app' directory.
4949
.WithResourceMapping(new FileInfo("appsettings.json"), "/app/")
5050
// Copy 'appsettings.Container.json' to '/app/appsettings.Developer.json'.
@@ -54,7 +54,7 @@ _ = new ContainerBuilder()
5454
Another overloaded member of the container builder API allows you to copy the contents of a byte array to a specific file path within the container. This can be useful when you already have the file content stored in memory or when you need to dynamically generate the file content before copying it.
5555

5656
```csharp title="Copying a byte array"
57-
_ = new ContainerBuilder()
57+
_ = new ContainerBuilder("alpine:3.20.0")
5858
.WithResourceMapping(Encoding.Default.GetBytes("{}"), "/app/appsettings.json");
5959
```
6060

@@ -63,7 +63,7 @@ _ = new ContainerBuilder()
6363
When copying files into a container, you can specify the user ID (UID) and group ID (GID) to set the correct ownership of the copied files. This is particularly useful when the container runs as a non-root user or when specific file permissions are required for security or application functionality.
6464

6565
```csharp title="Copying a file with specific UID and GID"
66-
_ = new ContainerBuilder()
66+
_ = new ContainerBuilder("alpine:3.20.0")
6767
.WithResourceMapping(new DirectoryInfo("."), "/app/", uid: 1000, gid: 1000);
6868
```
6969

@@ -72,7 +72,7 @@ _ = new ContainerBuilder()
7272
When copying files into a container, you can specify the file mode to set the correct permissions for the copied files.
7373

7474
```csharp title="Copying a script with executable permissions"
75-
_ = new ContainerBuilder()
75+
_ = new ContainerBuilder("alpine:3.20.0")
7676
.WithResourceMapping(new DirectoryInfo("."), "/app/", fileMode: Unix.FileMode755);
7777
```
7878

@@ -120,7 +120,7 @@ The `WithOutputConsumer` method is part of the `ContainerBuilder` class and is u
120120
```csharp title="Forwarding all log messages"
121121
using IOutputConsumer outputConsumer = Consume.RedirectStdoutAndStderrToConsole();
122122

123-
_ = new ContainerBuilder()
123+
_ = new ContainerBuilder("alpine:3.20.0")
124124
.WithOutputConsumer(outputConsumer);
125125
```
126126

@@ -146,7 +146,7 @@ If a module applies default commands and you need to override or remove them ent
146146
// .WithCommand("-c", "synchronous_commit=off")
147147
// ...
148148
149-
var postgreSqlContainer = new PostgreSqlBuilder()
149+
var postgreSqlContainer = new PostgreSqlBuilder("postgres:15.1")
150150
.WithCommand(new OverwriteEnumerable<string>(Array.Empty<string>()))
151151
.Build();
152152
```
@@ -164,9 +164,8 @@ An NGINX container that binds the HTTP port to a random host port and hosts stat
164164
```csharp
165165
const ushort HttpPort = 80;
166166

167-
var nginxContainer = new ContainerBuilder()
167+
var nginxContainer = new ContainerBuilder("nginx:1.26.3-alpine3.20")
168168
.WithName(Guid.NewGuid().ToString("D"))
169-
.WithImage("nginx")
170169
.WithPortBinding(HttpPort, true)
171170
.Build();
172171

@@ -189,9 +188,8 @@ const string MagicNumber = "42";
189188

190189
const ushort MagicNumberPort = 80;
191190

192-
var deepThoughtContainer = new ContainerBuilder()
191+
var deepThoughtContainer = new ContainerBuilder("alpine:3.20.0")
193192
.WithName(Guid.NewGuid().ToString("D"))
194-
.WithImage("alpine")
195193
.WithPortBinding(MagicNumberPort, true)
196194
.WithEnvironment("MAGIC_NUMBER", MagicNumber)
197195
.WithEntrypoint("/bin/sh", "-c")

docs/api/create_docker_network.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,17 @@ var network = new NetworkBuilder()
2929
.WithName(Guid.NewGuid().ToString("D"))
3030
.Build();
3131

32-
var deepThoughtContainer = new ContainerBuilder()
32+
var deepThoughtContainer = new ContainerBuilder("alpine:3.20.0")
3333
.WithName(Guid.NewGuid().ToString("D"))
34-
.WithImage("alpine")
3534
.WithEnvironment("MAGIC_NUMBER", MagicNumber)
3635
.WithEntrypoint("/bin/sh", "-c")
3736
.WithCommand($"while true; do echo \"$MAGIC_NUMBER\" | nc -l -p {MagicNumberPort}; done")
3837
.WithNetwork(network)
3938
.WithNetworkAliases(MagicNumberHost)
4039
.Build();
4140

42-
var ultimateQuestionContainer = new ContainerBuilder()
41+
var ultimateQuestionContainer = new ContainerBuilder("alpine:3.20.0")
4342
.WithName(Guid.NewGuid().ToString("D"))
44-
.WithImage("alpine")
4543
.WithEntrypoint("top")
4644
.WithNetwork(network)
4745
.Build();

docs/api/low_level_api_access.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ Testcontainers does not expose all available [Docker Engine APIs](https://docs.d
44

55
```csharp title="Setting the memory limit to 2GB"
66
const long TwoGB = 2L * 1024 * 1024 * 1024;
7-
_ = new ContainerBuilder()
7+
_ = new ContainerBuilder("alpine:3.20.0")
88
.WithCreateParameterModifier(parameterModifier => parameterModifier.HostConfig.Memory = TwoGB);
99
```

docs/api/resource_reaper.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ Creates a scoped Resource Reaper and assigns its session id to a container (Dock
1616
var resourceReaper = await ResourceReaper.GetAndStartNewAsync()
1717
.ConfigureAwait(false);
1818
19-
await new ContainerBuilder()
20-
.WithImage("alpine")
19+
await new ContainerBuilder("alpine:3.20.0")
2120
.WithResourceReaperSessionId(resourceReaper.SessionId)
2221
.Build()
2322
.StartAsync()

docs/api/resource_reuse.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
Reuse is an experimental feature designed to simplify and enhance the development experience. Instead of disposing resources after the tests are finished, enabling reuse will retain the resources and reuse them in the next test run. Testcontainers assigns a hash value according to the builder configuration. If it identifies a matching resource, it will reuse this resource instead of creating a new one. Enabling reuse will disable the resource reaper, meaning the resource will not be cleaned up.
44

55
```csharp title="Enable container reuse"
6-
_ = new ContainerBuilder()
6+
_ = new ContainerBuilder("alpine:3.20.0")
77
.WithReuse(true);
88
```
99

1010
The reuse implementation does currently not consider (support) all builder APIs when calculating the hash value. Therefore, collisions may occur. To prevent collisions, simply use a distinct label to identify the resource.
1111

1212
```csharp title="Label container resource to identify it"
13-
_ = new ContainerBuilder()
13+
_ = new ContainerBuilder("alpine:3.20.0")
1414
.WithReuse(true)
1515
.WithLabel("reuse-id", "WeatherForecast");
1616
```

docs/api/wait_strategies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ HEALTHCHECK --interval=1s CMD test -e /healthcheck
103103
You can leverage the container's health status as your wait strategy to report readiness of your application or service:
104104

105105
```csharp
106-
_ = new ContainerBuilder()
106+
_ = new ContainerBuilder("alpine:3.20.0")
107107
.WithWaitStrategy(Wait.ForUnixContainer().UntilContainerIsHealthy());
108108
```
109109

docs/examples/aspnet.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private sealed class RedisConfigurationProvider : ConfigurationProvider
5959

6060
public async Task LoadAsync()
6161
{
62-
var redisContainer = new RedisBuilder().Build();
62+
var redisContainer = new RedisBuilder("redis:7.0").Build();
6363

6464
await redisContainer.StartAsync()
6565
.ConfigureAwait(false);
@@ -93,13 +93,12 @@ const string connectionString = $"server={weatherForecastStorage};user id={MsSql
9393
_weatherForecastNetwork = new NetworkBuilder()
9494
.Build();
9595

96-
_msSqlContainer = new MsSqlBuilder()
96+
_msSqlContainer = new MsSqlBuilder("mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04")
9797
.WithNetwork(_weatherForecastNetwork)
9898
.WithNetworkAliases(weatherForecastStorage)
9999
.Build();
100100

101-
_weatherForecastContainer = new ContainerBuilder()
102-
.WithImage(Image)
101+
_weatherForecastContainer = new ContainerBuilder(Image)
103102
.WithNetwork(_weatherForecastNetwork)
104103
.WithPortBinding(WeatherForecastImage.HttpsPort, true)
105104
.WithEnvironment("ASPNETCORE_URLS", "https://+")

docs/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ dotnet add package Testcontainers
66

77
```csharp title="Run the Hello World container"
88
// Create a new instance of a container.
9-
var container = new ContainerBuilder()
10-
// Set the image for the container to "testcontainers/helloworld:1.3.0".
11-
.WithImage("testcontainers/helloworld:1.3.0")
9+
var container = new ContainerBuilder("testcontainers/helloworld:1.3.0")
1210
// Bind port 8080 of the container to a random port on the host.
1311
.WithPortBinding(8080, true)
1412
// Wait until the HTTP endpoint of the container is available.

docs/modules/cassandra.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ You can start an Apache Cassandra container instance from any .NET application.
1212

1313
=== "Start a Cassandra container"
1414
```csharp
15-
var cassandraContainer = new CassandraBuilder().Build();
15+
var cassandraContainer = new CassandraBuilder("cassandra:5.0").Build();
1616
await cassandraContainer.StartAsync();
1717
```
1818

0 commit comments

Comments
 (0)