docker networking

Jasmin shahrzad
Jasmin shahrzad used Ask the Experts™
i have an ssh-sftp container on my ubuntu.
from ubuntu i add ip for container ( docker inspect "container_id")
then i can ssh and sftp from my ubuntu server to container
how to do it out of ubuntu server (on my domain)?
where to add container's ip for ssh or sftp to container?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Can't quite figure out what you're asking.

Maybe you're asking how to connect access ssh + sftp inside your Docker container from external connections.

Place an update if this is what you mean.
nociSoftware Engineer
Distinguished Expert 2018

please describe your container in more detail.
How do you start it.

Does your container show any thing under the column PORTS
that would mean you can use the host address with the ports mentioned before the ->

If those entries don't exist then you need to keep your containers,  it will reuse the address until the container is removed.
You need to run you container with -p so ports are forwarded or possibly expose them in the dockerfile
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


ok it was me.
my ftp server shows following port under docker ps>2121/tcp,>22/tcp
and i can start          user_name_in_sftp@my_contiainer_ip -p 2222
then i login to sftp server. is it a way to login without sending port 2222 ? i can not use port 22 in my docker-compose.
when i say ports   "22:22"  in my docker-compose.  docker failed
failed : Error starting userland proxy: listen tcp bind: address already in use


i can login to sftp server via ssh (with user i created under create image)
 i login with my user (or with docker exec -it "sftp_server" /bin/bash) and say
sudo useradd -d /upload -G sftp upload -s /usr/sbin/nologin
and add password for upload user echo "upload:opload123" | sudo chpasswd
/upload is in my docker-compose as volumes then i say sudo chown upload:sftp -R /upload
i can't sftp to my container
i say sftp upload@container-ip  it ask for password i write password
failed Permission denied, please try again.
can you see what it's wrong what i missing?


I try following in filezila:
sftp://container-ip. "username". "password"  port=2222

answer:                 fzSftp started, protocol_version=8
command :       open "user-name@container-ip" 2222
command:       Pass: *********
Failed:                  Server unexpectedly closed network connection
Failed:                  Can not connect to server
nociSoftware Engineer
Distinguished Expert 2018

try: container-ip:2222. "usernane"   etc.
(convention is hostname:portnumber  or hostname:portname in the host field to use another port.
or ithas a separate option like sft -p
if you are using default options, you need to connect to the host's address. not the container's.

default options use NAT to provide the container network connectivity. the private addresses the container uses are not known to the rest of the network.

... and your container must be run with "docker run ... -p 2222:2222 ...." ( you obviously can use different ports )

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial