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]: bash shell required for InternalCommandPortListeningCheck #6730

Open
longliveenduro opened this issue Mar 6, 2023 · 4 comments
Open
Labels

Comments

@longliveenduro
Copy link

Module

Core

Testcontainers version

1.17.6

Using the latest Testcontainers version?

Yes

Host OS

Ubutntu

Host Arch

x86

Docker version

Client: Docker Engine - Community
 Version:           23.0.1
 API version:       1.42
 Go version:        go1.19.5
 Git commit:        a5ee5b1
 Built:             Thu Feb  9 19:46:56 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.1
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.5
  Git commit:       bc3805a
  Built:            Thu Feb  9 19:46:56 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.18
  GitCommit:        2456e983eb9e37e47538f59ea18f2043c9a73640
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

What happened?

I try to create a docker compose test and it spins up correctly. My base image is alpine which has no bash.

Then I get a

19:12:35.916 [testcontainers-wait-0] WARN  org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck - An exception while executing the internal check: Container.ExecResult(exitCode=137, stdout=, stderr=/bin/sh: /bin/bash: not found
``

### Relevant log output

```shell
19:12:35.916 [testcontainers-wait-0] WARN  org.testcontainers.containers.wait.internal.InternalCommandPortListeningCheck - An exception while executing the internal check: Container.ExecResult(exitCode=137, stdout=, stderr=/bin/sh: /bin/bash: not found

Additional Information

No response

@longliveenduro
Copy link
Author

If I check

command.append(String.format("/bin/bash -c '</dev/tcp/localhost/%d'", internalPort));

I see there a bash -c ...

Is this intended?

@leonard84
Copy link
Contributor

leonard84 commented Mar 22, 2023

I just run into this problem when trying to run a busybox image, which doesn't have bash installed.
#2195 seems to be related.

Turns out, that it was a red-herring in my case, although it the command failed it wasn't the actual problem.

@perlun
Copy link
Contributor

perlun commented Jun 9, 2023

Hi @leonard84 and @longliveenduro, I'm the author of #2195. The idea is this:

command.append(" (");
command.append(String.format("grep -i ':0*%x' /proc/net/tcp*", internalPort));
command.append(" || ");
command.append(String.format("nc -vz -w 1 localhost %d", internalPort));
command.append(" || ");
command.append(String.format("/bin/bash -c '</dev/tcp/localhost/%d'", internalPort));
command.append(")");

  • First try grepping in /proc/net/tcp*
  • If there are no matches, try nc -vz -w 1 localhost %d
  • If that also fails, as a final step, try /bin/bash -c '</dev/tcp/localhost/%d'

The /dev/tcp/localhost/<port> is a bashism, so this check really cannot be performed without bash. But the first check (grep -i ':0*%x' /proc/net/tcp*) should normally work if the port is listening in the container.

@furstenheim-goodnotes
Copy link

furstenheim-goodnotes commented Nov 27, 2024

Is it possible to optionally disable this check? I'm using spicedb which uses chainguard it doesn't even have sh.

Then the check always fails and I'm never able to reuse the image

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

No branches or pull requests

4 participants