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










0















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!










share|improve this question


























    0















    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!










    share|improve this question
























      0












      0








      0


      0






      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!










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 21 at 17:01









      AnnAnn

      1




      1






















          1 Answer
          1






          active

          oldest

          votes


















          0














          .withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".



          Use .withExposedPorts(22) instead.






          share|improve this answer























          • 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












          • 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











          • 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











          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
          );



          );













          draft saved

          draft discarded


















          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









          0














          .withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".



          Use .withExposedPorts(22) instead.






          share|improve this answer























          • 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












          • 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











          • 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















          0














          .withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".



          Use .withExposedPorts(22) instead.






          share|improve this answer























          • 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












          • 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











          • 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













          0












          0








          0







          .withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".



          Use .withExposedPorts(22) instead.






          share|improve this answer













          .withExposedPorts(port) - it seems that you're trying to externalize the port, while you image defines a static port "22".



          Use .withExposedPorts(22) instead.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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 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












          • 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

















          • 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












          • 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











          • 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
















          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



















          draft saved

          draft discarded
















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해