Docker Community Forums

Share and learn in the Docker community.

SSH connection doesn't work

Hi, I’ve created a vsftpd docker using Fauria image (https://hub.docker.com/r/fauria/vsftpd/). I want to access it throw ssh so I’ve mapped in the docker-compose file the port 22 with the port 3022, I’ve installed openssh-clients and server, I’ve edited the sshd_config file enabling root login and I’ve assigned a password to the system. Now from my PC I was trying to connect using “ssh -p 3022 root@<my.ip>”.
The result is a connection refused and I cannot understand why. Does anyone ever use ssh to connect to a docker? What am I doing wrong?
Thanks to everybody! :slight_smile:

Trying to connect using SSH to your docker container :sweat_smile: You should use docker exec ... instead

More to the point. It should work.
On the host (as root), check that docker-proxy does indeed serve 3022 using : netstat -ltnp|grep docker-proxy (but since you got a “connection refused”, it’s probably closed)
Then check that sshd is indeed running in the container using docker exec <id> ps aux
Otherwise, you probably inverted port numbers in the compose file. Since that use to happen to me a lot, Now, I’m using the syntax :

    ports:
      - target: 22
        published: 3022

which is, by far, clearer than - 3022:22

Thank you for the tip of the ports!
Anyways I need to move a file using a python script from a docker to an FTP-server docker. The two dockers may not be in the same local machine. I tried using FTP connection but, for some reason that I couldn’t understand, the login takes 40sec each time and this is not possible. So I was searching a new way to copy a file and I discovered ssh, I’ve used it sometimes in the past but not for this specific job.
Now I will try again the ssh connection, if someone has a better way to copy files from a docker to another I will be very happy to learn more :grin: :grin: