testcontainers / testcontainers-dotnet

A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
https://dotnet.testcontainers.org
MIT License
3.65k stars 250 forks source link

Testcontainers.MsSql Returns Docker Error about Conflict During Integration Tests #1127

Closed terryaney closed 4 months ago

terryaney commented 4 months ago

Testcontainers version

3.6.0

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host arch

x86

.NET version

7

Docker version

Client:
 Cloud integration: v1.0.35+desktop.10
 Version:           25.0.3
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        4debf41
 Built:             Tue Feb  6 21:13:02 2024
 OS/Arch:           windows/amd64
 Context:           default

Server: Docker Desktop 4.27.2 (137060)
 Engine:
  Version:          25.0.3
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       f417435
  Built:            Tue Feb  6 21:14:25 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Docker info

Client:
 Version:    25.0.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1-desktop.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-buildx.exe
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.5-desktop.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-compose.exe
  debug: Get a shell into any image or container. (Docker Inc.)
    Version:  0.0.24
    Path:     C:\Program Files\Docker\cli-plugins\docker-debug.exe
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-dev.exe
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.21
    Path:     C:\Program Files\Docker\cli-plugins\docker-extension.exe
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.4
    Path:     C:\Program Files\Docker\cli-plugins\docker-feedback.exe
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.0.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-init.exe
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     C:\Program Files\Docker\cli-plugins\docker-sbom.exe
  scout: Docker Scout (Docker Inc.)
    Version:  v1.4.1
    Path:     C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server:
 Containers: 3
  Running: 2
  Paused: 0
  Stopped: 1
 Images: 5
 Server Version: 25.0.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.6.12-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 1.92GiB
 Name: docker-desktop
 ID: 390214ef-1e7b-4ca6-87f7-359cd0ff84d2
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile

What happened?

I develop on a laptop and desktop using the same repository, but Testcontainers.MsSql has a fail rate of about 95% on the desktop, while a 100% success rate on the laptop. The error I get on my desktop for all my tests is:

Docker.DotNet.DockerApiException : Docker API responded with status code=Conflict, response={"message":"container 181ed4bbfa292f8cbf9a6f17cf7abada437af1ea37eb9f810150c18c83ded3d1 is not running"}

However, while I watch Docker Desktop, I can see images/containers starting up and stopping in what seems like a normal fashion. I have Docker Desktop 4.27.2 on my desktop and 4.27.1 on my laptop.

I've seen other issues asking for enabling logs but I haven't discovered how to enable them yet. My code in a derived WebApplicationFactory<T> is simply:

private readonly MsSqlContainer msSqlContainer = 
    new MsSqlBuilder()
        .Build();

public virtual async Task InitializeAsync()
{
    await msSqlContainer.StartAsync();
}

Any ideas of why the Desktop mostly doesn't work? Let me know if there is more information I can provide. (FYI, posted similar question on Stackoverflow and got close votes, not sure why, hoping it is because they want it here).

Relevant log output

No response

Additional information

No response

HofmeisterAn commented 4 months ago

Could you please share the actual container logs? The logs contain the reasons why the container suddenly exited.

HofmeisterAn commented 4 months ago

It looks like your Docker VM only provides 2GB of RAM. According to the docs this might not be enough.

At least 2GB of RAM (3.25 GB prior to 2017-CU2). Make sure to assign enough memory to the Docker VM if you're running on Docker for Mac or Windows.

terryaney commented 4 months ago

It looks like your Docker VM only provides 2GB of RAM. According to the docs this might not be enough.

Great eye. This fixed it, thanks a lot. In case I ever have problems in the future, where are these:

Could you please share the actual container logs? The logs contain the reasons why the container suddenly exited.

HofmeisterAn commented 4 months ago

In case I ever have problems in the future, where are these:

Either use the Docker CLI command docker container logs or access them by selecting the container in Docker Desktop and opening Logs in the top menu bar.

image

Since the issue seems to be resolved, I will close it in the meantime. If you have further questions, do not hesitate to reopen it again.