Yes, this is expected if you have not SSH'ed into the docker container.
Connection to 10.0.0.10 22 port [tcp/ssh] succeeded!
is seen in the VM because you have SSH'ed into the VM as ssh [email protected]
and port 22
is used in the VM for SSH.
But, when you are inside a docker container (using docker run
or docker exec
or docker attach
), port 22
will not be used, and hence the following error from nc
is expected inside the docker container:
10.0.0.10: inverse host lookup failed: Unknown host
(UNKNOWN) [10.0.0.10] 22 (ssh) open
Here are the steps to successfully test if port 80
is used using nc
inside an nginx
docker container:
$ sudo docker run --name docker-nginx -d -p 80:80 nginx
$ sudo docker exec -it docker-nginx /bin/bash
root@60ec582e90f4:/# apt-get -y update
root@60ec582e90f4:/# apt-get -y upgrade
root@60ec582e90f4:/# apt-get install -y net-tools
root@60ec582e90f4:/# apt-get install -y netcat
# make sure that port 80 is used
root@60ec582e90f4:/# netstat -pan | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1/nginx: master pro
# nc will work now inside the nginx container as port 80 is used inside the container
root@60ec582e90f4:/# nc -vz 127.0.0.1 80 -w 4
localhost [127.0.0.1] 80 (?) open
Hence, for nc -vz a.b.c.d P -w 4
to work inside a container, port P
must be used on IP address a.b.c.d
inside that container.