Skip to content

Commit c1b76c5

Browse files
committed
docs: Add platform doc
1 parent 4f4b6ad commit c1b76c5

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/api/create_docker_container.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
Testcontainers' generic container support offers the greatest flexibility and makes it easy to use virtually any container image in the context of a temporary test environment. To interact or exchange data with a container, Testcontainers provides `ContainerBuilder` to configure and create the resource.
44

5+
## Configure container image
6+
7+
Use `WithImage(...)` to specify the container image.
8+
9+
The simplest overload accepts a `string`:
10+
11+
```csharp
12+
_ = new ContainerBuilder()
13+
.WithImage("postgres:15.1");
14+
```
15+
16+
For platform-specific scenarios, `WithImage` also accepts an `IImage`. Using the `DockerImage` implementation, you can explicitly set the platform:
17+
18+
```csharp
19+
_ = new ContainerBuilder()
20+
.WithImage(new DockerImage("postgres:15.1", "linux/amd64"));
21+
```
22+
523
## Configure container start
624

725
Both `ENTRYPOINT` and `CMD` allows you to configure an executable and parameters, that a container runs at the start. By default, a container will run whatever `ENTRYPOINT` or `CMD` is specified in the Docker container image. At least one of both configurations is necessary. The container builder implementation supports `WithEntrypoint(params string[])` and `WithCommand(params string[])` to set or override the executable. Ideally, the `ENTRYPOINT` should set the container's executable, whereas the `CMD` sets the default arguments for the `ENTRYPOINT`.

src/Testcontainers/Images/DockerfileArchive.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ private static string ReplaceVariables(string line, IDictionary<string, string>
401401

402402
if (quote != null)
403403
{
404-
throw new FormatException($"Unmatched {quote} quote starting at position {start - 1} in line: '{line}'.");
404+
throw new FormatException($"Unmatched {quote} quote in line: '{line}'.");
405405
}
406406

407407
if (line.Length > start)
@@ -426,7 +426,7 @@ private static (string Name, string Value) ParseFlag(string flag)
426426
else
427427
{
428428
var name = trimmed.Substring(0, eqIndex);
429-
var value = trimmed.Substring(eqIndex + 1).Trim(' ', '"', '\'');
429+
var value = trimmed.Substring(eqIndex + 1).Trim().Trim('"', '\'');
430430
return (name, value);
431431
}
432432
}

0 commit comments

Comments
 (0)