Can't connect to docker via ssh using testcontainer The Next CEO of Stack OverflowHow to use SSH to run a shell script on a remote machine?ssh “permissions are too open” errorHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersCould not open a connection to your authentication agentCopying files from Docker container to hostCopying files from host to Docker container
WOW air has ceased operation, can I get my tickets refunded?
What flight has the highest ratio of time difference to flight time?
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
multiple labels for a single equation
Novel about a guy who is possessed by the divine essence and the world ends?
How are problems classified in Complexity Theory?
Why is the US ranked as #45 in Press Freedom ratings, despite its extremely permissive free speech laws?
Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?
Indicator light circuit
In excess I'm lethal
What is ( CFMCC ) on ILS approach chart?
If Nick Fury and Coulson already knew about aliens (Kree and Skrull) why did they wait until Thor's appearance to start making weapons?
How did the Bene Gesserit know how to make a Kwisatz Haderach?
Is there a difference between "Fahrstuhl" and "Aufzug"
Won the lottery - how do I keep the money?
Return the Closest Prime Number
What was the first Unix version to run on a microcomputer?
At which OSI layer a user-generated data resides?
Contours of a clandestine nature
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Interfacing a button to MCU (and PC) with 50m long cable
If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?
Which tube will fit a -(700 x 25c) wheel?
Is micro rebar a better way to reinforce concrete than rebar?
Can't connect to docker via ssh using testcontainer
The Next CEO of Stack OverflowHow to use SSH to run a shell script on a remote machine?ssh “permissions are too open” errorHow is Docker different from a virtual machine?Should I use Vagrant or Docker for creating an isolated environment?How to list containers in DockerHow to get a Docker container's IP address from the host?How to remove old Docker containersCould not open a connection to your authentication agentCopying files from Docker container to hostCopying files from host to Docker container
My task is connected to the container via ssh from tests.
I have dockefile: (almost from https://docs.docker.com/engine/examples/running_ssh_service/)
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' |chpasswd
RUN sed -i 's/^#?PermitRootLogins+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed 's@sessions*requireds*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
RUN mkdir /root/.ssh
RUN apt-get clean &&
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Then I use this dockerfile by testcontainer:
public static GenericContainer localServer(@NotNull Integer port, @NotNull String user, @NotNull String password, Path dockerfile) {
return new GenericContainer(
new ImageFromDockerfile()
.withFileFromPath("Dockerfile", dockerfile))
.withExposedPorts(port)
.withFileSystemBind(FileUtil.getTempDirectory(), "/home/", BindMode.READ_WRITE);
When I run my test, the container successfully runs, but I can't connect via ssh. 49154 - is value from sftp.getMappedPort(22)
ssh root@localhost -p 49154
Got:
ssh: connect to host localhost port 32836: Connection refused
What's a detail I've missed? Thanks!
docker ssh testcontainers
add a comment |
My task is connected to the container via ssh from tests.
I have dockefile: (almost from https://docs.docker.com/engine/examples/running_ssh_service/)
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' |chpasswd
RUN sed -i 's/^#?PermitRootLogins+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed 's@sessions*requireds*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
RUN mkdir /root/.ssh
RUN apt-get clean &&
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Then I use this dockerfile by testcontainer:
public static GenericContainer localServer(@NotNull Integer port, @NotNull String user, @NotNull String password, Path dockerfile) {
return new GenericContainer(
new ImageFromDockerfile()
.withFileFromPath("Dockerfile", dockerfile))
.withExposedPorts(port)
.withFileSystemBind(FileUtil.getTempDirectory(), "/home/", BindMode.READ_WRITE);
When I run my test, the container successfully runs, but I can't connect via ssh. 49154 - is value from sftp.getMappedPort(22)
ssh root@localhost -p 49154
Got:
ssh: connect to host localhost port 32836: Connection refused
What's a detail I've missed? Thanks!
docker ssh testcontainers
add a comment |
My task is connected to the container via ssh from tests.
I have dockefile: (almost from https://docs.docker.com/engine/examples/running_ssh_service/)
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' |chpasswd
RUN sed -i 's/^#?PermitRootLogins+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed 's@sessions*requireds*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
RUN mkdir /root/.ssh
RUN apt-get clean &&
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Then I use this dockerfile by testcontainer:
public static GenericContainer localServer(@NotNull Integer port, @NotNull String user, @NotNull String password, Path dockerfile) {
return new GenericContainer(
new ImageFromDockerfile()
.withFileFromPath("Dockerfile", dockerfile))
.withExposedPorts(port)
.withFileSystemBind(FileUtil.getTempDirectory(), "/home/", BindMode.READ_WRITE);
When I run my test, the container successfully runs, but I can't connect via ssh. 49154 - is value from sftp.getMappedPort(22)
ssh root@localhost -p 49154
Got:
ssh: connect to host localhost port 32836: Connection refused
What's a detail I've missed? Thanks!
docker ssh testcontainers
My task is connected to the container via ssh from tests.
I have dockefile: (almost from https://docs.docker.com/engine/examples/running_ssh_service/)
FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo 'root:root' |chpasswd
RUN sed -i 's/^#?PermitRootLogins+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed 's@sessions*requireds*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
RUN mkdir /root/.ssh
RUN apt-get clean &&
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
Then I use this dockerfile by testcontainer:
public static GenericContainer localServer(@NotNull Integer port, @NotNull String user, @NotNull String password, Path dockerfile) {
return new GenericContainer(
new ImageFromDockerfile()
.withFileFromPath("Dockerfile", dockerfile))
.withExposedPorts(port)
.withFileSystemBind(FileUtil.getTempDirectory(), "/home/", BindMode.READ_WRITE);
When I run my test, the container successfully runs, but I can't connect via ssh. 49154 - is value from sftp.getMappedPort(22)
ssh root@localhost -p 49154
Got:
ssh: connect to host localhost port 32836: Connection refused
What's a detail I've missed? Thanks!
docker ssh testcontainers
docker ssh testcontainers
asked Mar 21 at 17:01
AnnAnn
1
1
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
.withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".
Use .withExposedPorts(22) instead.
Thanks, but “port” is actually constant = “22”.
– Ann
Mar 23 at 16:42
then make sure that your image actually listens on all interfaces, not just "localhost". Have you tried to run it with justdocker run -p 22 my-image?
– bsideup
Mar 24 at 10:47
Yes, I also can run docker with the terminal only:dockerfile docker build -t image_name .docker run -d -P --name container_name image_namedocker port test_sshd 22ssh root@localhost -p 32768and it works
– Ann
Mar 25 at 12:55
just in case, my OS is macOS
– Ann
Mar 25 at 13:53
In yourdocker runexample, you didn't map the/home/folder, but I see this in the example code you provided. Could you please double check that it is not caused by it?
– bsideup
Mar 26 at 11:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285629%2fcant-connect-to-docker-via-ssh-using-testcontainer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
.withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".
Use .withExposedPorts(22) instead.
Thanks, but “port” is actually constant = “22”.
– Ann
Mar 23 at 16:42
then make sure that your image actually listens on all interfaces, not just "localhost". Have you tried to run it with justdocker run -p 22 my-image?
– bsideup
Mar 24 at 10:47
Yes, I also can run docker with the terminal only:dockerfile docker build -t image_name .docker run -d -P --name container_name image_namedocker port test_sshd 22ssh root@localhost -p 32768and it works
– Ann
Mar 25 at 12:55
just in case, my OS is macOS
– Ann
Mar 25 at 13:53
In yourdocker runexample, you didn't map the/home/folder, but I see this in the example code you provided. Could you please double check that it is not caused by it?
– bsideup
Mar 26 at 11:30
add a comment |
.withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".
Use .withExposedPorts(22) instead.
Thanks, but “port” is actually constant = “22”.
– Ann
Mar 23 at 16:42
then make sure that your image actually listens on all interfaces, not just "localhost". Have you tried to run it with justdocker run -p 22 my-image?
– bsideup
Mar 24 at 10:47
Yes, I also can run docker with the terminal only:dockerfile docker build -t image_name .docker run -d -P --name container_name image_namedocker port test_sshd 22ssh root@localhost -p 32768and it works
– Ann
Mar 25 at 12:55
just in case, my OS is macOS
– Ann
Mar 25 at 13:53
In yourdocker runexample, you didn't map the/home/folder, but I see this in the example code you provided. Could you please double check that it is not caused by it?
– bsideup
Mar 26 at 11:30
add a comment |
.withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".
Use .withExposedPorts(22) instead.
.withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".
Use .withExposedPorts(22) instead.
answered Mar 22 at 15:01
bsideupbsideup
58138
58138
Thanks, but “port” is actually constant = “22”.
– Ann
Mar 23 at 16:42
then make sure that your image actually listens on all interfaces, not just "localhost". Have you tried to run it with justdocker run -p 22 my-image?
– bsideup
Mar 24 at 10:47
Yes, I also can run docker with the terminal only:dockerfile docker build -t image_name .docker run -d -P --name container_name image_namedocker port test_sshd 22ssh root@localhost -p 32768and it works
– Ann
Mar 25 at 12:55
just in case, my OS is macOS
– Ann
Mar 25 at 13:53
In yourdocker runexample, you didn't map the/home/folder, but I see this in the example code you provided. Could you please double check that it is not caused by it?
– bsideup
Mar 26 at 11:30
add a comment |
Thanks, but “port” is actually constant = “22”.
– Ann
Mar 23 at 16:42
then make sure that your image actually listens on all interfaces, not just "localhost". Have you tried to run it with justdocker run -p 22 my-image?
– bsideup
Mar 24 at 10:47
Yes, I also can run docker with the terminal only:dockerfile docker build -t image_name .docker run -d -P --name container_name image_namedocker port test_sshd 22ssh root@localhost -p 32768and it works
– Ann
Mar 25 at 12:55
just in case, my OS is macOS
– Ann
Mar 25 at 13:53
In yourdocker runexample, you didn't map the/home/folder, but I see this in the example code you provided. Could you please double check that it is not caused by it?
– bsideup
Mar 26 at 11:30
Thanks, but “port” is actually constant = “22”.
– Ann
Mar 23 at 16:42
Thanks, but “port” is actually constant = “22”.
– Ann
Mar 23 at 16:42
then make sure that your image actually listens on all interfaces, not just "localhost". Have you tried to run it with just
docker run -p 22 my-image?– bsideup
Mar 24 at 10:47
then make sure that your image actually listens on all interfaces, not just "localhost". Have you tried to run it with just
docker run -p 22 my-image?– bsideup
Mar 24 at 10:47
Yes, I also can run docker with the terminal only:
dockerfile docker build -t image_name . docker run -d -P --name container_name image_name docker port test_sshd 22 ssh root@localhost -p 32768 and it works– Ann
Mar 25 at 12:55
Yes, I also can run docker with the terminal only:
dockerfile docker build -t image_name . docker run -d -P --name container_name image_name docker port test_sshd 22 ssh root@localhost -p 32768 and it works– Ann
Mar 25 at 12:55
just in case, my OS is macOS
– Ann
Mar 25 at 13:53
just in case, my OS is macOS
– Ann
Mar 25 at 13:53
In your
docker run example, you didn't map the /home/ folder, but I see this in the example code you provided. Could you please double check that it is not caused by it?– bsideup
Mar 26 at 11:30
In your
docker run example, you didn't map the /home/ folder, but I see this in the example code you provided. Could you please double check that it is not caused by it?– bsideup
Mar 26 at 11:30
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55285629%2fcant-connect-to-docker-via-ssh-using-testcontainer%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown