2

I have docker running on a server and I deployed a container, by running:

docker run -d -p docker_server_ip:3001:22 --name test14 -ti rhel_7_4

When running docker ps I can see the instance.

Also, I see that Docker server is listening:

netstat -ntalp | grep 3001
tcp        0      0 docker_server_ip:3001       0.0.0.0:*               LISTEN      10362/docker-proxy

If I try to ssh to this container I get 'connection refused' (linux iptables is off).

ssh root@docker_server_ip -p 3001 - "ssh: connect to host docker_server_ip port 3001: Connection refused"

What am I missing?

5
  • Please edit the question with the exact ssh command you are using when trying to connect.
    – dirkt
    Sep 8, 2019 at 15:13
  • Is the "iptables is off" part of the error message? If yes, I suspect that iptables is not working properly on your server, for whatever reason (docker needds iptables).
    – dirkt
    Sep 9, 2019 at 6:34
  • in many other systems i saw iptables is off
    – Miki
    Sep 9, 2019 at 6:39
  • What is in the rhel_7_4 image? Are you running a sshd server inside your container? If so, that's a sign of an anti-pattern. And if not, there's nothing to connect to.
    – BMitch
    Sep 11, 2019 at 15:00
  • @Miki did you install openssh-server on the docker, set PermitRootLogin yes in sshd_config, and created passwd for root user ?
    – Noam Manos
    Jan 22, 2020 at 9:20

1 Answer 1

0

It is not recommended to run SSH server inside container, see why and best practices in this blog post.

For example, to copy files from Docker, use:

docker cp {container_name}:{file_path} {target_file_path OR target_dir_ended_with_slash}

However, if you really need ssh (for example, the container runs on a remote host), make sure the container runs sshd, here's how I do it:

  • Install sshd and vi: sudo apt install -y openssh-server vim
  • Set PermitRootLogin yes in sshd_config: sudo vi /etc/ssh/sshd_config
  • Restart sshd service: sudo service ssh restart
  • Add a password to root user: sudo passwd

Then you should be able to connect with SSH.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .