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

Wait.UntilPortsAreAvailable throws exception if the container doesn't have bash #178

Closed
jdelucaa opened this issue Jan 7, 2020 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@jdelucaa
Copy link
Contributor

jdelucaa commented Jan 7, 2020

Describe the bug
When building a container with Wait.UntilPortsAreAvailable, I get an expection when starting the container:

Docker.DotNet.DockerApiException: 'Docker API responded with status code=BadRequest, response={"message":"OCI runtime exec failed: exec failed: container_linux.go:346: starting container process caused "exec: \"/bin/bash\": stat /bin/bash: no such file or directory": unknown"}

This is because my container doesn't have bash installed, only sh or other implementation of shell..

To Reproduce
Steps to reproduce the behavior:

var fhirServerContainerBuilder = new TestcontainersBuilder<TestcontainersContainer>()
        .WithImage("conceptant/hapi-fhir")
        .WithPortBinding(8080, true)
        .WithCleanUp(true)
        .WithWaitStrategy(Wait.UntilPortsAreAvailable(8080));

      using (var fhirServerContainer = fhirServerContainerBuilder.Build())
      {
        await fhirServerContainer.StartAsync();
      }

Expected behavior
The commands used to verify the availability of the ports should support other shells.

Screenshots
Not necessary

Desktop (please complete the following information):

  • Linux container
  • Docker for Windows version 19.03.5, build 633a0ea

Additional context
I did the following changes to the code that solved the problem

In WaitUntilBashCommandsAreCompleted.cs changed from /bin/bash to bin/sh - because sh will point to the actual implementation of the shell ( bash, dash, etc.. ), I think it'll work for most cases.

The expcetion was gone with that change, but the thread got stucked somewhere, I figured there was something wrong with the command used in WaitUntilPortsAreAvailable.cs, for some reason that command doesn't work in my container, it says the directory does not exist, so I changed the line 8 from timeout 15 bash -c \"echo > /dev/tcp/localhost/8080\" to a boolean expression with some ways to try and check if the port is available (like the testcontainers-java version does): true && (cat /proc/net/tcp{{,6}} | awk '{{print $2}}' | grep -i :{port} || nc -vz -w 1 localhost {port} || /bin/bash -c '</dev/tcp/localhost/{port}');

Those changes saved my day... let me know if you think it's a good solution to open a PR to fix the issue.

@HofmeisterAn
Copy link
Collaborator

@jdelucaa thanks for your effort, you're right. Of course, we're supposed to follow the standard, especially if we don't need any bash specific implementations.

I think it's a good idea to switch to sh and I would love to see a PR. I'm not sure the command covers all cases, but we will see if the unit tests succeed.

We should probably rename WaitUntilBashCommandsAreCompleted too and replace /bin/bash with /bin/sh in the unit tests. What do you think?

If you need any help, let me know.

@HofmeisterAn HofmeisterAn added the bug Something isn't working label Jan 7, 2020
@HofmeisterAn HofmeisterAn added this to the 1.1.0 milestone Jan 7, 2020
@jdelucaa
Copy link
Contributor Author

jdelucaa commented Jan 8, 2020

PR #179

HofmeisterAn pushed a commit that referenced this issue Jan 8, 2020
…ilPortsAreAvailable'

{Added multiple commands to verify port availability}
HofmeisterAn pushed a commit that referenced this issue Jan 8, 2020
…ilBashCommandsAreCompleted.Until'

{Changed to use /bin/sh instead of /bin/bash to execute the commands}
HofmeisterAn pushed a commit that referenced this issue Jan 8, 2020
…ashCommandsAreCompleted'

{Renamed to WaitUntilShellCommandsAreCompleted}
@HofmeisterAn
Copy link
Collaborator

@jdelucaa I'll check #180 and #181 and probably release a new minor version after that. Until then you could use 1.1.0-beta.20200108.2. FYI: You should check our Git config email address. It seems like the address is not connected to your GitHub account. You would like to use a private address anyway for public commits: https://help.github.com/assets/images/help/settings/email_privacy.png.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants