How to connect docker network to external network

Hi Everyone!

I have deployed docker desktop with Linux container and my requirement is Linux container should connect with outside network.
Need your suggestion how to achieve this.

How do you want to connect? Dou you need a dedicated LAN IP address or is port forward enough? What is your use case?

Hi ,
Thanks for your response.

I want to connect Linux docker container via putty tool from external network.

Hi,
do you have any solution to connect Linux docker container via putty tool from external network.

Sorry I forgot about you. Does “connect via putty tool” means you want to use SSH to log in the container?

If you have everything in the container you need, then search for “docker port forward”. You will find this probably as the first result:

But I guess you already knew that and you still can’t connect.

So check your firewall settings. On Windows you need to open the port on the firewall:

Rimelek,

Thanks for the response.
my requirement is to access the container from my laptop with putty.
How can I achieve this

Please, react to my recommendations what you have already tried and what you know, because I think I gave you all the information you need but I don’t know if you tried what I suggested so I cannot give you more advice.

Rimelek,

Yes, I did changes as per your suggestion, but still the issue persist.

What did you change? Sorry I try to follow you but if you don’t tell me what you did exactly then we can misunderstand eachother. Just today I helped one of my colleagues and he did almost everything right in theory so I couldn’t help him until he showed me his config file which contained a space on the first line…

Rimelek,

I could not explain everything on the chat, so it will be worth if you take my system access and would show you the error practically for better understanding. let me know if you are ok with it.

How would that work? Would it be a user and a password to log in and see something you can’t share here.
From your point of view sharing such personal data would not be wise. I trust myself but you know… you shouldn’t :slight_smile: If you could write step by step what you did, that would be the best like

  1. I created a Docker Image which contains an SSH service
  2. The SSH service is running, I tested it using ps command (or netstat)
  3. I don’t know the IP address of the container so I can’t use putty to access the container
  4. Docker exec works but I really need SSH

So this is what I thought you could do. Just some very clear steps so I know what you are trying to achieve because putty is just a program to use SSH or telnet as far as I know but you still didn’t describe how you want to use it. I think it is explainable on a forum but if you try it and that is not enough, I will consider what you suggested

Hi Rimelek,

Thanks for your response. Indeed I will not share my PC considering you point.

However I have tried to write the steps followed for the installation

On windows 10 PC, deployed docker desktop.
In Windows PowerShell, executed this “Docker run -t -d –name red Ubuntu 22:04” and installed image.
Started docker container with this command " docker start red".
Verified using “docker PS” and Docker container was running
Entered in to Linux container with “docker exec -it red bash” .
In the container, verified ping status by pinging to website google.com, and it was pinging.
Enabled ssh in the container.

After performing the above steps. By default I have now container IP assigned by bridge network is 172.17.0.2.

In Windows Firewall, set rule for inbound and outbound as per the instruction in the document given by you.

With this IP 172.17.0.2 i am trying to access the container through putty from my PC and landing with error “connection timed out”

My requirement is to establish communication between the docker containers and the outside world via host machine with putty.
Hope I tried to convey my problem with this :slightly_smiling_face:

I expected an explanation exactly you gave me now :slight_smile:

This would not work so I am sure you didn’t executed the quoted command but I will suppose you did it correctly and quoted wrong.

docker run starts the container. This step is not necessary unless you stop the container first.

You can’t use the the internal IP address from Windows given by Docker.

I thought you did what I suggested in my first comment:

This is required on Windows even if you want to connect from the same machine because it is not the same machine from the Docker’s point of view. The containers are in a virtual machine so you need to use docker run with -p HOSTPORT:CONTAINERPORT and access your container using the host port.

I don’t actively use Docker Desktop so if anyone knows another way, correct me :slight_smile: