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

Container exists instantly after startup #5

Closed
wis-niowy opened this issue Jul 14, 2023 · 2 comments
Closed

Container exists instantly after startup #5

wis-niowy opened this issue Jul 14, 2023 · 2 comments

Comments

@wis-niowy
Copy link

wis-niowy commented Jul 14, 2023

Hi, I'm trying to run a test container based on testcontainers/sshd:1.1.0 image.

Here is my code that attempts to do so:

var container = new ContainerBuilder()
            .WithImage("testcontainers/sshd:1.1.0")
            .WithPortBinding(22, true)
            .WithExposedPort(22)
            .WithDockerEndpoint("tcp://localhost:2375")
            .Build();

await container.StartAsync();

When running the code I lookup the Docker Desktop - and I can see that the container gets created, starts running and then instantly exits (with code 0).
What looks odd is that port mapping actually is 0:22 - so it apparently failed to assign a random port of my local machine.
When I select a port for the mapping, e.g. .WithPortBinding(55548, 22), the mapping in the Docker Desktop looks fine (55548:22) - but the container still exits instantly.

The exception that I get in the code is: System.TimeoutException : The operation has timed out.

Everything is fine when I use testcontainers/helloworld:1.1.0 image, with the following code:

var container = new ContainerBuilder()
            .WithImage("testcontainers/helloworld:1.1.0")
            .WithPortBinding(8080, true)
            .WithExposedPort(8080)
            .WithDockerEndpoint("tcp://localhost:2375")
            .Build();

await container.StartAsync();

The container stands up and runs properly - and I can successfully hit it with http request (via HttpClinet()).

So I am wondering if I am missing something or there is an issue with this image.
testcontainers/helloworld does not meet my requirements as I need an instance with a sshd running to test my ssh/sftp client locally.

My OS is Windows 10.

@theshubhamp
Copy link

theshubhamp commented Feb 17, 2024

Happens because the Docker image is not setup with an entrypoint that starts up SSHD.

Permitting root login and configuring the demon to not detach gets it working:

docker run -it -p 9022:22 testcontainers/sshd sh -c 'echo "PermitRootLogin yes" >> /etc/ssh/sshd_config; /usr/sbin/sshd -D'

Is this repo / image still maintained ? If so, I can send in a PR. Otherwise can be work around on ContainerBuilder directly.

@mdelapenya
Copy link
Member

This image is used by the testcontainers libraries to provide an SSH tunnel, exposing host ports to a container. We fixed this in #7, so switching to testcontainers/ssh:1.2.0 would work out-of-the-box for you.

For that reason I'm closing this issue. Thanks!

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

No branches or pull requests

3 participants