Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Peet-HD committed May 17, 2024
2 parents 24f1ca5 + ac58b9f commit 754260a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.3.0"/>
<PackageVersion Include="BouncyCastle.Cryptography" Version="2.3.1"/>
<PackageVersion Include="Docker.DotNet.X509" Version="3.125.15"/>
<PackageVersion Include="Docker.DotNet" Version="3.125.15"/>
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0"/>
Expand Down
11 changes: 11 additions & 0 deletions docs/api/create_docker_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@ _ = new ImageFromDockerfileBuilder()
!!!tip

Testcontainers for .NET detects your Docker host configuration. You do **not** have to set the Docker daemon socket.

## Known issues

- When building an image using Testcontainers for .NET and switching the user's context (`USER` statement) in a Dockerfile, the user won't automatically become the [owner](https://github.com/testcontainers/testcontainers-dotnet/issues/1171#issuecomment-2099197840) of the working directory, which seems to be the case when building the image from the CLI. If the running process requires write access to the working directory, it is necessary to set the permissions explicitly (the base image in this example already contains the user `app`):

```Dockerfile
FROM mcr.microsoft.com/dotnet/sdk:8.0
WORKDIR /app
RUN chown app:app .
USER app
```
20 changes: 12 additions & 8 deletions docs/examples/dind.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Running inside another container

## Docker Desktop
## 'Docker wormhole' pattern - Sibling Docker containers

### Sibling containers
### Docker-only example

If you choose to run your tests in a Docker Wormhole configuration, which involves using sibling containers, it is necessary to mount Docker's raw socket `/var/run/docker.sock.raw`. You find more information and an explanation of the Docker bug in this [comment](https://github.com/docker/for-mac/issues/5588#issuecomment-934600089).

```console
docker run -v /var/run/docker.sock.raw:/var/run/docker.sock $IMAGE dotnet test
```

### Compose
!!! note
If you are using Docker Desktop, you need to configure the `TESTCONTAINERS_HOST_OVERRIDE` environment variable to use the special DNS name
`host.docker.internal` for accessing the host from within a container, which is provided by Docker Desktop:
`-e TESTCONTAINERS_HOST_OVERRIDE=host.docker.internal`

### Docker Compose example

To use Docker's Compose tool to build and run a Testcontainers environment in a Docker Desktop Wormhole configuration,
it is necessary to override Testcontainers' Docker host resolution and set the environment variable `TESTCONTAINERS_HOST_OVERRIDE` to `host.docker.internal`.
Otherwise, Testcontainers cannot access sibling containers like the Resource Reaper Ryuk or other services running on the Docker host.
A minimal `docker-compose.yml` file that builds a new container image and runs the test inside the container look something like:

```yaml
Expand All @@ -26,8 +28,10 @@ services:
context: .
entrypoint: dotnet
command: test
environment:
- TESTCONTAINERS_HOST_OVERRIDE=host.docker.internal
# Uncomment the lines below in the case of Docker Desktop (see note above).
# TESTCONTAINERS_HOST_OVERRIDE is not needed in the case of Docker Engine.
# environment:
# - TESTCONTAINERS_HOST_OVERRIDE=host.docker.internal
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```
8 changes: 7 additions & 1 deletion src/Testcontainers/Images/DockerfileArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace DotNet.Testcontainers.Images
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
Expand Down Expand Up @@ -148,7 +149,12 @@ public async Task<string> Tar(CancellationToken ct = default)
using (var inputStream = new FileStream(absoluteFilePath, FileMode.Open, FileAccess.Read))
{
var entry = TarEntry.CreateTarEntry(relativeFilePath);
entry.Size = inputStream.Length;
entry.TarHeader.Size = inputStream.Length;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
entry.TarHeader.Mode = (int)Unix.FileMode755;
}

await tarOutputStream.PutNextEntryAsync(entry, ct)
.ConfigureAwait(false);
Expand Down

0 comments on commit 754260a

Please sign in to comment.