8

I am running docker containers on Google Cloud virtual machine. I am trying for hours to connect from filezilla on my local computer to an running docker container. I have started docker image like this:

docker run -t -d --name test -p 2222:22 --link postgres7:postgres7 random_image /bin/bash

In my filezilla connection configuration I have set:

Host: Google Cloud IP address
Port: 2222
Protocol: SFTP
Logon Type: Normal
User: root (without password)

When trying to connect I get this error:

Status: Connecting to x.x.x.x:2222...
Response:   fzSftp started
Command:    open "root@x.x.x.x" 2222
Error:  Connection refused
Error:  Could not connect to server

I have opened ports on google cloud engine.

Tomislav Brabec
  • 529
  • 2
  • 14
  • 20

2 Answers2

5

First, it is not recommended to install ssh server on docker containers but here is how I did it:

  1. Install ssh client

apt-get install openssh-server

  1. Set password on root (or any user you want to connect with)

passwd (enter password twice)

  1. In /etc/ssh/sshd_config change:

PermitRootLogin without-password

to

PermitRootLogin yes

  1. Restart ssh server

/etc/init.d/ssh restart

And now you will be able to connect with any ftp client as root to your docker container with password that you set.

Tomislav Brabec
  • 529
  • 2
  • 14
  • 20
  • its a centos 7 docker image from fauria/docker-vsftpd, after doing all this it says no such file /etc/init.d/ssh, also systemctl restart sshd and service sshd restart also not working if you have tried at your hand? – aniruddha Jan 05 '18 at 16:36
  • @aniruddha I have only tried this on ubuntu 14.04 and 16.04 and it is working for me. I am not sure for CentOS. Did you try /etc/init.d/ssh restart. Also, maybe it would be neccessary to add --privileged option to docker run. – Tomislav Brabec May 21 '18 at 13:03
0

You have to sudo nano /etc/ssh/sshd_config, then search with Ctrl + W for PasswordAuth and modify it to yes.

Then you can try login in via sftp:// to your IP through Port 22.