Search code examples
dockersshcentossshd

How to get my docker centos sshd passwordless server running?


I'm running my docker container with:

docker run -d sequenceiq/hadoop-docker:2.6.0

The Dockerfile is here.

After it is started on my mac - I'm running docker ps and getting:

6bfa4f2fd3b5        sequenceiq/hadoop-docker:2.6.0   "/etc/bootstrap.sh -d"   4 minutes ago       Up 4 minutes        22/tcp, 8030-8033/tcp, 8040/tcp, 8042/tcp, 8088/tcp, 49707/tcp, 50010/tcp, 50020/tcp, 50070/tcp, 50075/tcp, 50090/tcp   kind_hawking

Then I'm running

ssh -v localhost -p 22

and I'm getting

OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/User/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to localhost [::1] port 22.
debug1: connect to address ::1 port 22: Connection refused
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: connect to address 127.0.0.1 port 22: Connection refused
ssh: connect to host localhost port 22: Connection refused

Assumptions: I think this is not a duplicate of the other centos sshd questions as this is a different centos version. (For those that are similar - it is doing what the potentially similar question is asking and it is not working).

My question is: How to get my docker centos sshd passwordless server running?


Edit: @Andrew has been super-helpful in helping me refine my question - so here goes.

Here is my updated Dockerfile

FROM sequenceiq/hadoop-docker:2.6.0

CMD ["/etc/bootstrap.sh", "-d"]

# Hdfs ports
EXPOSE 50010 50020 50070 50075 50090 8020 9000
# Mapred ports
EXPOSE 10020 19888
#Yarn ports
EXPOSE 8030 8031 8032 8033 8040 8042 8088
#Other ports
EXPOSE 49707 2122

EXPOSE 9000

EXPOSE 2022

Now I'm building this with:

 sudo docker build -t my-hdfs .

Then I'm running this with:

sudo docker run -d -p my-hdfs 

Then I'm checking the processes with:

sudo docker ps

with a result like:

d9c9855cfaf0        my-hdfs             "/etc/bootstrap.sh -d"   2 minutes ago       
Up 2 minutes        0.0.0.0:32801->22/tcp, 0.0.0.0:32800->2022/tcp, 
0.0.0.0:32799->2122/tcp, 0.0.0.0:32798->8020/tcp, 0.0.0.0:32797->8030/tcp, 
0.0.0.0:32796->8031/tcp, 0.0.0.0:32795->8032/tcp, 0.0.0.0:32794->8033/tcp, 
0.0.0.0:32793->8040/tcp, 0.0.0.0:32792->8042/tcp, 0.0.0.0:32791->8088/tcp, 
0.0.0.0:32790->9000/tcp, 0.0.0.0:32789->10020/tcp, 0.0.0.0:32788->19888/tcp, 
0.0.0.0:32787->49707/tcp, 0.0.0.0:32786->50010/tcp, 0.0.0.0:32785->50020/tcp, 
0.0.0.0:32784->50070/tcp, 0.0.0.0:32783->50075/tcp, 0.0.0.0:32782->50090/tcp   
agitated_curran

Then to get the IP address I'm running:

docker inspect --format '{{ .NetworkSettings.IPAddress }}' d9c9855cfaf0

with a result like

172.17.0.3

Then I'm testing it with:

ssh -v 172.17.0.3 -p 32800

This gives a result:

OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/User/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 172.17.0.3 [172.17.0.3] port 32800.

debug1: connect to address 172.17.0.3 port 32800: Operation timed out
ssh: connect to host 172.17.0.3 port 32800: Operation timed out

My question is: How to get my docker centos sshd passwordless server running?


Solution

  • You are trying to connect to you local ssh server instead of container. To connect to any port inside container, you need to expose and publish it and possibly map it to another one, especially in case when you want to run multiple similar containers on different ports on the same host. See Expose.

    So in your case your command should be

    docker run -p 2222:22 -d sequenceiq/hadoop-docker:2.6.0 
    

    And ssh command

    ssh -v localhost -p 2222
    

    Exposing docker port (as seen in your linked docker file) makes it accessible to other docker containers, but not to your host machine. To understand difference between exposed and published ports see this question

    However, when i tried to connect to port 2222 it haven't worked. Looking at Dockerfile of 2.6.0 version, i've found that it has a bug, where sshd configured to listen on port 2122, but exposed port is 22, as can be seen here. Also, when i'm tried to build a lastest Dockerfile you provided, it failed at step 31, so you might want to inverstigate further.

    Edit after question update:

    Look at docker ps output you provided, and on Dockerfile. sshd configured to listen on port 2122 (if you haven’t changed that though since we don't have a complete dockerfile of yours), and in output we see

    0.0.0.0:32799->2122/tcp
    0.0.0.0:32800->2022/tcp
    

    You should connect as ssh -v localhost -p 32799 instead of 32800 since nothing is listening on port 2022 inside container