From 0075c73590a462cb8a4794de2feb028d04ff3698 Mon Sep 17 00:00:00 2001 From: Stefan Lobbenmeier Date: Thu, 17 Oct 2024 12:43:55 +0200 Subject: [PATCH] Document how to use this container for exposing host ports (#17) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Document how to use this container for host port forwarding * Update README.md Co-authored-by: Manuel de la Peña * Update README.md --------- Co-authored-by: Manuel de la Peña --- README.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/README.md b/README.md index 169178c..b8d9776 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,40 @@ # sshd-docker Docker image with SSH daemon installed + +# Usage +This container is meant to be used to expose host ports to containers running in Docker. +When using testcontainers in unit tests, refer to the documentation of testcontainers to find out how to use it: +- Java: https://java.testcontainers.org/features/networking/#exposing-host-ports-to-the-container +- .NET: https://dotnet.testcontainers.org/api/create_docker_network/#exposing-host-ports-to-the-container +- node.js: https://node.testcontainers.org/features/networking/#expose-host-ports-to-container +- Go: https://golang.testcontainers.org/features/networking/#exposing-host-ports-to-the-container + +Alternatively, you can start the container yourself: +```yaml +services: + sshd: + image: testcontainers/sshd:1.2.0 + environment: + PASSWORD: "SET_YOUR_PASSWORD_HERE" + ports: + - 10022:22 + + requester: + image: curlimages/curl + command: /bin/sh -c "while true; do curl http://sshd:8080; sleep 5; done" + depends_on: + - sshd +``` + +And connect to it via ssh: + +```bash +# ssh -R [remote_port]:[destination_address]:[local_port] [username]@[ssh_server] -p [ssh_port] +ssh -R 8080:localhost:8080 root@localhost -p 10022 +``` + +Start your application and you should see requests coming from the requester service: + +```bash +python3 -m http.server 8080 +```