testcontainers-go
testcontainers-go copied to clipboard
[Bug]: Error response from daemon: Container xxx is not running: failed to start container
Testcontainers version
v0.14.0
Using the latest Testcontainers version?
Yes
Host OS
mac os
Host Arch
arm64
Go Version
1.18
Docker version
Client:
Cloud integration: v1.0.22
Version: 20.10.12
API version: 1.41
Go version: go1.16.12
Git commit: e91ed57
Built: Mon Dec 13 11:46:56 2021
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.12
API version: 1.41 (minimum version 1.12)
Go version: go1.16.12
Git commit: 459d0df
Built: Mon Dec 13 11:43:07 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.4.12
GitCommit: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Docker info
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.7.1)
compose: Docker Compose (Docker Inc., v2.2.3)
scan: Docker Scan (Docker Inc., v0.16.0)
Server:
Containers: 5
Running: 3
Paused: 0
Stopped: 2
Images: 45
Server Version: 20.10.12
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
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 logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
cgroupns
Kernel Version: 5.10.76-linuxkit
Operating System: Docker Desktop
OSType: linux
Architecture: aarch64
CPUs: 4
Total Memory: 7.765GiB
Name: docker-desktop
ID: U7YH:5NKK:7UVH:2ANG:AE2O:453P:IPSR:TPLS:3K6C:RJ2X:JYA7:SI7T
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
What happened?
ctx := context.Background()
req := testcontainers.ContainerRequest{
Image: "bitnami/git",
WaitingFor: wait.ForExec([]string{"git", "version"}),
}
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
log.Errorf("gereicContainer failed: %v", err)
}
defer container.Terminate(ctx)
Relevant log output
2022/09/21 09:51:30 Starting container id: 1484f961520d image: docker.io/testcontainers/ryuk:0.3.3
2022/09/21 09:51:31 Waiting for container id 1484f961520d image: docker.io/testcontainers/ryuk:0.3.3
2022/09/21 09:51:31 Container is ready id: 1484f961520d image: docker.io/testcontainers/ryuk:0.3.3
2022/09/21 09:51:31 Starting container id: d5f4a31b066e image: bitnami/git
2022/09/21 09:51:31 Waiting for container id d5f4a31b066e image: bitnami/git
2022-09-21T09:51:31.578+0800 ERROR log/log.go:177 gereicContainer failed: Error response from daemon: Container d5f4a31b066ed8aad0b60832bf8978786064787ea4f7bcd5b17d9ea7791e4d33 is not running: failed to start container
snippets.robertzwj.com/internal/pkg/log.Errorf
Additional Information
No response
Hi @robertzhangwenjie I've identified what's going on here.
I think the issue you are experiencing comes from the base image itself: because an entrypoint is not defined, then the container starts and stops immediately.
You need to pass an entrypoint to the ContainerRequest that keeps the container up and running for ever, so that your wait.ForExec strategy hits the container. Using your own example, but adding the entrypoint, it works as expected (printing the git version):
func TestMissingEntrypoint(t *testing.T) {
ctx := context.Background()
req := ContainerRequest{
Image: "bitnami/git",
Entrypoint: []string{"tail", "-f", "/dev/null"},
WaitingFor: wait.ForExec([]string{"git", "version"}),
}
container, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: req,
Started: true,
})
if err != nil {
t.Fatalf("genericContainer failed: %v", err)
}
defer container.Terminate(ctx)
c, reader, err := container.Exec(ctx, []string{"git", "--version"})
if err != nil {
t.Fatalf("genericContainer failed: %v", err)
}
if c > 0 {
t.Fatalf("genericContainer failed: %v", err)
}
buf := new(strings.Builder)
_, err = io.Copy(buf, reader)
// check errors
fmt.Println(buf.String())
}
Is this what you would expect from the usage of tc-go?
Hi @robertzhangwenjie I'm going to close this issue as stale.
Feel free to reopen it if you consider it's not completed. Thanks in advance for using the library!