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.77k stars 272 forks source link

[Bug]: PostgreSqlBuilder ERROR: exec: \"-c\": executable file not found in $PATH: unknown" #1277

Open Taya1993 opened 11 hours ago

Taya1993 commented 11 hours ago

Testcontainers version

3.10.0

Using the latest Testcontainers version?

Yes

Host OS

Windows

Host arch

x64

.NET version

EFCore 6

Docker version

Client: Version: 27.2.0 API version: 1.47 Go version: go1.21.13 Git commit: 3ab4256 Built: Tue Aug 27 14:17:17 2024 OS/Arch: windows/amd64 Context: desktop-linux

Server: Docker Desktop 4.34.3 (170107) Engine: Version: 27.2.0 API version: 1.47 (minimum version 1.24) Go version: go1.21.13 Git commit: 3ab5c7d Built: Tue Aug 27 14:15:15 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.7.20 GitCommit: 8fc6bcff51318944179630522a095cc9dbf9f353 runc: Version: 1.1.13 GitCommit: v1.1.13-0-g58aa920 docker-init: Version: 0.19.0 GitCommit: de40ad0

Docker info

Client: Version: 27.2.0 Context: desktop-linux Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc.) Version: v0.16.2-desktop.1 Path: C:\Program Files\Docker\cli-plugins\docker-buildx.exe compose: Docker Compose (Docker Inc.) Version: v2.29.2-desktop.2 Path: C:\Program Files\Docker\cli-plugins\docker-compose.exe debug: Get a shell into any image or container (Docker Inc.) Version: 0.0.34 Path: C:\Program Files\Docker\cli-plugins\docker-debug.exe desktop: Docker Desktop commands (Alpha) (Docker Inc.) Version: v0.0.15 Path: C:\Program Files\Docker\cli-plugins\docker-desktop.exe dev: Docker Dev Environments (Docker Inc.) Version: v0.1.2 Path: C:\Program Files\Docker\cli-plugins\docker-dev.exe extension: Manages Docker extensions (Docker Inc.) Version: v0.2.25 Path: C:\Program Files\Docker\cli-plugins\docker-extension.exe feedback: Provide feedback, right in your terminal! (Docker Inc.) Version: v1.0.5 Path: C:\Program Files\Docker\cli-plugins\docker-feedback.exe init: Creates Docker-related starter files for your project (Docker Inc.) Version: v1.3.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.13.0 Path: C:\Program Files\Docker\cli-plugins\docker-scout.exe

Server: Containers: 1 Running: 0 Paused: 0 Stopped: 1 Images: 4 Server Version: 27.2.0 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: 1 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog Swarm: inactive Runtimes: io.containerd.runc.v2 nvidia runc Default Runtime: runc Init Binary: docker-init containerd version: 8fc6bcff51318944179630522a095cc9dbf9f353 runc version: v1.1.13-0-g58aa920 init version: de40ad0 Security Options: seccomp Profile: unconfined Kernel Version: 5.15.153.1-microsoft-standard-WSL2 Operating System: Docker Desktop OSType: linux Architecture: x86_64 CPUs: 8 Total Memory: 7.664GiB Name: docker-desktop ID: e6b9f3e8-b556-4edd-b490-24cb6bf1b6cf 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 Labels: com.docker.desktop.address=npipe://\.\pipe\docker_cli Experimental: false Insecure Registries: hubproxy.docker.internal:5555 127.0.0.0/8 Registry Mirrors: https://mirror.gcr.io/ https://daocloud.io/ https://c.163.com/ https://registry.docker-cn.com/ Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support WARNING: No blkio throttle.write_bps_device support WARNING: No blkio throttle.read_iops_device support WARNING: No blkio throttle.write_iops_device support WARNING: daemon is not using the default seccomp profile

What happened?

Created a docker image based on a docker container (used "docker commit ..."). Therefore, the last two commands in the layers CMD ["postgres" "-c" "listen_addresses=0.0.0.0" "-c" "shared_buffers=256MB" "-c" "shared_preload_libraries=ldc_cache,verstamp_xid"] and postgres -c listen_addresses=0.0 .0.0 -c shared_buffers=256MB -c shared_preload_libraries=ldc_cache,verstamp_xid Last command appears after "docker commit ..."

Then I want to use:

private const string PostgresImage = "path to my image"; private PostgreSqlContainer pgContainer;

this.pgContainer = new PostgreSqlBuilder() .WithImage(PostgresImage) .WithName($"pg_testdb{Guid.NewGuid()}") .WithDatabase("MY_AUTOTEST") .WithPortBinding(5435, true) .WithUsername("postgres") .WithPassword("passw4") .WithAutoRemove(true) .WithCleanUp(true) .Build();

await this.pgContainer.StartAsync();

But when StartAsync, I get an error

Docker.DotNet.DockerApiException : Docker API responded with status code=BadRequest, response={"message":"failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: \"-c\": executable file not found in $PATH: unknown"}

I think problem with layer postgres -c listen_addresses=0.0 .0.0 -c shared_buffers=256MB -c shared_preload_libraries=ldc_cache,verstamp_xid

But why ok working ContainerBuilder with the same image?

        this.pgContainer = new ContainerBuilder()
            .WithImage(PostgresImage)
            .WithPortBinding(5435, true)
            .WithName($"pg_test_db_{Guid.NewGuid()}")
            .WithEnvironment(new Dictionary<string, string>
            {
                { "POSTGRES_USER", "postgres"},
                { "POSTGRES_PASSWORD", "passw4"},
                { "POSTGRES_DB", "MY_AUTOTEST"},
            })
            .WithAutoRemove(true)
            .WithCleanUp(true)
            .Build();

Relevant log output

No response

Additional information

No response

HofmeisterAn commented 11 hours ago

Created a docker image based on a docker container (used "docker commit ...").

If you are using a "custom" image, you cannot expect a module to work with it. Modules are pre-configured and opinionated. In this case, use the generic builder ContainerBuilder instead.