Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: docker.host parameter doesn't work anymore #1338

Closed
also1366 opened this issue Jul 4, 2023 · 2 comments · Fixed by #1517
Closed

[Bug]: docker.host parameter doesn't work anymore #1338

also1366 opened this issue Jul 4, 2023 · 2 comments · Fixed by #1517
Labels
bug An issue with the library

Comments

@also1366
Copy link

also1366 commented Jul 4, 2023

Testcontainers version

0.21.0

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host arch

x86

Go version

1.20

Docker version

Server: Docker Engine - Community
 Engine:
  Version:          24.0.2
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.4
  Git commit:       659604f
  Built:            Thu May 25 21:52:17 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
 rootlesskit:
  Version:          1.1.0
  ApiVersion:       1.1.1
  NetworkDriver:    slirp4netns
  PortDriver:       builtin
  StateDir:         /tmp/rootlesskit1968203600
 slirp4netns:
  Version:          1.0.1
  GitCommit:        6a7b16babc95b6a3056b33fb45b74a6f62262dd4

Docker info

Client: Docker Engine - Community
 Version:    24.0.2
 Context:    rootless
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.10.5
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.18.1
    Path:     /usr/libexec/docker/cli-plugins/docker-compose
  scan: Docker Scan (Docker Inc.)
    Version:  v0.23.0
    Path:     /usr/libexec/docker/cli-plugins/docker-scan

Server:
 Containers: 12
  Running: 9
  Paused: 0
  Stopped: 3
 Images: 444
 Server Version: 24.0.2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: false
  userxattr: true
 Logging Driver: json-file
 Cgroup Driver: systemd
 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 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dce8eb055cbb6872793272b4f20ed16117344f8
 runc version: v1.1.7-0-g860f061
 init version: de40ad0
 Security Options:
  seccomp
   Profile: builtin
  rootless
  cgroupns
 Kernel Version: 6.1.0-0.deb11.7-amd64
 Operating System: Debian GNU/Linux 11 (bullseye)
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 30.96GiB
 Name: hamlet
 ID: OHFM:AHIA:VZBD:46XM:4WBY:HAF5:7A4F:LWAD:YKMU:FZ3O:XZXO:YHCX
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Username: whoisxmlapi
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

What happened?

I have a .testcontainers.properties file in my home directory:
docker.host=unix:///var/run/user/1000/docker.sock

The library reads the docker host and strips "unix://" part.
Then it provides the host "/var/run/user/1000/docker.sock" to the docker library.
Though the docker library expects the host to start with "unix://" and throws an error.

It works fine for me in version 0.20.1

When I run the test with the env variable DOCKER_HOST=unix:///var/run/user/1000/docker.sock it works.
It doesn't strip "unix://".

I read this PR that behaviour somewhat changed, but I don't understand what's happening.
#1161

Am I doing something wrong?

Relevant log output

=== RUN   TestContainers/TestElasticsearch
Testcontainers properties file has been found: /home/user/.testcontainers.properties
    main_test.go:37: failed to start container: unable to parse docker host `/var/run/user/1000/docker.sock`, failed to create Docker provider

Additional information

No response

@also1366 also1366 added the bug An issue with the library label Jul 4, 2023
@mdelapenya
Copy link
Member

mdelapenya commented Aug 23, 2023

Hi @also1366 thanks for opening this bug report.

I'm adding this unit test to the docker_host_test.go and it fails:

	t.Run("Unix Docker Host is passed as docker.host", func(t *testing.T) {
		content := "docker.host=" + DockerSocketSchema + "/this/is/a/sample.sock"

		setupTestcontainersProperties(t, content)

		host := extractDockerHost(context.Background())

		assert.Equal(t, DockerSocketSchema + "/this/is/a/sample.sock", host)
	})

I'm taking a look at how Java does this: https://java.testcontainers.org/features/configuration/#customizing-docker-host-detection, and I think we have to fix the dockerHostFromProperties function to not parse the URL, and to behave as the DOCKER_HOST env var, as you suggests.

// dockerHostFromProperties returns the docker host from the ~/.testcontainers.properties file, if it's not empty
func dockerHostFromProperties(ctx context.Context) (string, error) {
	cfg := config.Read()
	socketPath := cfg.Host
	if socketPath != "" {
-		parsed, err := parseURL(socketPath)
-		if err != nil {
-			return "", err
-		}
-
-		return parsed, nil
+		return socketPath, nil
	}

	return "", ErrDockerSocketNotSetInProperties
}

I'm checking with the other maintainers internally, but it feels that we should change this as shown above. Will ping you back

@mdelapenya
Copy link
Member

@also1366 we merged the PR so if you are able to check the latest commit from main, it should be fixed

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants