How to login to a container through ssh/Putty from another host

I have created a container with RHEL 7.4 inside a host with RHEL 7.4 as well.

I have used Macvlan network driver as shown in

So now I can ping the IP of my container from another host in the same network.

My host’s ip where docker is installed is 172.xx.xx.105 and another host’s ip is 172.xx.xx.106 and my container’s ip is 192.xx.x.10.

How can I ssh to my container’s IP(192.xx.x.10) from another host (172.xx.xx.106) or just directly ssh to my container’s ip directly from a putty?

you will have to install and start the ssh server in the container, as typically this isn’t in the starter image.

SSH is installed in the Container and I can ssh from the container to the another host without any problem.

The only problem is sshing from another host to the container.

Here is the message I receive

debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug2: resolving “192.xx.x.10” port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to 192.xx.x.10 [192.xx.x.10] port 22.
debug1: connect to address 192.xx.x.10 port 22: Connection refused
ssh: connect to host 192.xx.x.10 port 22: Connection refused

well, there is ssh client (the ssh command) and there is ssh server (sshd). you need the server installed on your container to be able to ssh into it from another system

And you need that the ssh server (sshd) is started in the container

Interesting stuff to read. Keep it up.

You would need to install and setup an SSH server in your container. Not sure why you need to ssh to your container.

If it’s a “simple” thing you are trying to do then you can always run a command in a running container using a docker container exec command. And using the Docker Client CLI (or API) you can run commands locally to the container, or remotely (requires setup and authentication).


I run a container from the httpd:latest Docker Official image and give it a name of apache

🐳  gforghetti:[~] $ docker container run -d --name apache httpd:latest
Unable to find image 'httpd:latest' locally
latest: Pulling from library/httpd
6ae821421a7d: Pull complete
0ceda4df88c8: Pull complete
24f08eb4db68: Pull complete
c3c78f43bd0f: Pull complete
bd71aacd8d1e: Pull complete
Digest: sha256:d12c036427f436978f2d4397ad2bd6b5b8f7b03003b7a1da084eb228ef25b7d2
Status: Downloaded newer image for httpd:latest

I can then execute a command in the apache container.

Here I’ll see what version of Linux is running in the apache container.

🐳  gforghetti:[~] $ docker container exec -it apache cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION="9 (stretch)"