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]: LocalStack doesn't start if Allow the default Docker socket to be used is unchecked #7678

Closed
eddumelendez opened this issue Oct 17, 2023 · 1 comment · Fixed by #7727

Comments

@eddumelendez
Copy link
Member

eddumelendez commented Oct 17, 2023

Module

LocalStack

Testcontainers version

1.19.1

Using the latest Testcontainers version?

Yes

Host OS

macos

Host Arch

ARM

Docker version

Client:
 Version:           24.0.6-rd
 API version:       1.43
 Go version:        go1.20.7
 Git commit:        da4c87c
 Built:             Wed Sep  6 16:40:13 2023
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.24.2 (124339)
 Engine:
  Version:          24.0.6
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.7
  Git commit:       1a79695
  Built:            Mon Sep  4 12:31:36 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.22
  GitCommit:        8165feabfdfe38c65b599c4993d227328c231fca
 runc:
  Version:          1.1.8
  GitCommit:        v1.1.8-0-g82f18fe
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

LocalStackContainer doesn't start when Allow the default Docker socket to be used (requires password) option in Docker Desktop for Mac is unchecked.

In the following method:

public String getRemoteDockerUnixSocketPath() {
if (this.strategy != null && this.strategy.allowUserOverrides()) {
String dockerSocketOverride = System.getenv("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE");
if (!StringUtils.isBlank(dockerSocketOverride)) {
return dockerSocketOverride;
}
}
if (this.strategy != null && this.strategy.getRemoteDockerUnixSocketPath() != null) {
return this.strategy.getRemoteDockerUnixSocketPath();
}
URI dockerHost = getTransportConfig().getDockerHost();
String path = "unix".equals(dockerHost.getScheme()) ? dockerHost.getRawPath() : "/var/run/docker.sock";
return SystemUtils.IS_OS_WINDOWS ? "/" + path : path;
}

strategy is null. After calling getTransportConfig().gerDockerHost(), the strategy will contain the right values and the docker host to be used.

Let's take into account that currently, LocalStackContainer tries to mount the docker socket in the constructor and at this point no strategy has been discovered yet. The following line

withFileSystemBind(DockerClientFactory.instance().getRemoteDockerUnixSocketPath(), "/var/run/docker.sock");

can also be moved to the configure method.

Relevant log output

13:24:08.639 INFO  org.testcontainers.images.PullPolicy - Image pull policy will be performed by: DefaultPullPolicy()
13:24:08.643 INFO  org.testcontainers.utility.ImageNameSubstitutor - Image name substitution will be performed by: DefaultImageNameSubstitutor (composite of 'ConfigurationFileImageNameSubstitutor' and 'PrefixingImageNameSubstitutor')
13:24:08.894 INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Loaded org.testcontainers.dockerclient.UnixSocketClientProviderStrategy from ~/.testcontainers.properties, will try it first
13:24:08.907 WARN  org.testcontainers.dockerclient.DockerClientProviderStrategy - DOCKER_HOST tcp://127.0.0.1:57810 is not listening
13:24:08.907 WARN  org.testcontainers.dockerclient.DockerClientProviderStrategy - DOCKER_HOST tcp://127.0.0.1:57810 is not listening
13:24:09.459 INFO  org.testcontainers.dockerclient.DockerClientProviderStrategy - Found Docker environment with Docker accessed via Unix socket (/Users/eddumelendez/.docker/run/docker.sock)
13:24:09.466 INFO  org.testcontainers.DockerClientFactory - Docker host IP address is localhost
13:24:09.488 INFO  org.testcontainers.DockerClientFactory - Connected to docker: 
  Server Version: 24.0.6
  API Version: 1.43
  Operating System: Docker Desktop
  Total Memory: 9951 MB
13:24:09.492 INFO  org.testcontainers.DockerClientFactory - Checking the system...
13:24:09.493 INFO  org.testcontainers.DockerClientFactory - ✔︎ Docker server version should be at least 1.6.0
13:24:09.534 INFO  tc.localstack/localstack:2.0 - LOCALSTACK_HOST environment variable set to localstack (to match last network alias on container with non-default network)
13:24:09.535 INFO  tc.localstack/localstack:2.0 - Creating container for image: localstack/localstack:2.0
13:24:09.652 INFO  org.testcontainers.utility.RegistryAuthLocator - Credential helper/store (docker-credential-osxkeychain) does not have credentials for https://index.docker.io/v1/
13:24:09.657 INFO  tc.testcontainers/ryuk:0.5.1 - Creating container for image: testcontainers/ryuk:0.5.1
13:24:09.743 INFO  tc.testcontainers/ryuk:0.5.1 - Container testcontainers/ryuk:0.5.1 is starting: a711c589efcd55a40c47f58b7a26e34de5a191b47578ae2a9bcc7c9f2c92a9bc
13:24:10.077 INFO  tc.testcontainers/ryuk:0.5.1 - Container testcontainers/ryuk:0.5.1 started in PT0.419S
13:24:10.386 INFO  tc.localstack/localstack:2.0 - Container localstack/localstack:2.0 is starting: f53fa14c54b7d6c0669d1316c34d6fe0540acf7557f0c5bde234e89a36a4c908
13:24:10.461 ERROR tc.localstack/localstack:2.0 - Could not start container
com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"error while creating mount source path '/host_mnt/Users/eddumelendez/.docker/run/docker.sock': mkdir /host_mnt/Users/eddumelendez/.docker/run/docker.sock: operation not supported"}

Additional Information

No response

eddumelendez added a commit that referenced this issue Oct 27, 2023
Currently, if `DockerClientFactory.instance().getRemoteDockerUnixSocketPath()`
is called without resolving the strategy then the remote docker socket
can be invalid, for example, using Docker Desktop for Mac with unchecked
`Allow the default Docker socket to be used` option.

Fixes #7678
eddumelendez added a commit that referenced this issue Oct 27, 2023
Currently, if `DockerClientFactory.instance().getRemoteDockerUnixSocketPath()`
is called without resolving the strategy then the remote docker socket
can be invalid, for example, using Docker Desktop for Mac with unchecked
`Allow the default Docker socket to be used` option.

Fixes #7678
@pdrosos
Copy link

pdrosos commented Oct 28, 2023

Hi @eddumelendez, do you plan to release a new version including this bugfix soon? I am using localstack testcontainer on MacBook M1 with MacOS Sonoma and docker via colima VM with vmType vz and mountType virtiofs. I have the same error (only from the localstack testcontainer, my other postgresql testcontainer works):

Caused by: org.testcontainers.containers.ContainerLaunchException: Container startup failed for image localstack/localstack:2.2.0
	at app//org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:359)
	at app//org.testcontainers.containers.GenericContainer.start(GenericContainer.java:334)
	at app//com.paysafe.rm.blacklists.configuration.aws.LocalStackConfiguration.localStackContainer(LocalStackConfiguration.java:30)
	at app//com.paysafe.rm.blacklists.configuration.aws.LocalStackConfiguration$$EnhancerBySpringCGLIB$$c7226098.CGLIB$localStackContainer$0(<generated>)
	at app//com.paysafe.rm.blacklists.configuration.aws.LocalStackConfiguration$$EnhancerBySpringCGLIB$$c7226098$$FastClassBySpringCGLIB$$ed1314e1.invoke(<generated>)
	at app//org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
	at app//org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
	at app//com.paysafe.rm.blacklists.configuration.aws.LocalStackConfiguration$$EnhancerBySpringCGLIB$$c7226098.localStackContainer(<generated>)
	at java.base@17.0.9/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base@17.0.9/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base@17.0.9/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base@17.0.9/java.lang.reflect.Method.invoke(Method.java:568)
	at app//org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	... 138 more
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
	at app//org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
	at app//org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:344)
	... 150 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
	at app//org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:564)
	at app//org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:354)
	at app//org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
	... 151 more
Caused by: com.github.dockerjava.api.exception.InternalServerErrorException: Status 500: {"message":"error while creating mount source path '/Users/pavlina.drosos/.colima/default/docker.sock': mkdir /Users/pavlina.drosos/.colima/default/docker.sock: operation not supported"}

The error happens only if I create colima VM with vmType vz and mountType virtiofs, if vmType qemu and mountType sshfs are used instead, then the localstack testcontainer works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants