Connect to the Docker container from host network - windows

I have a WcfService under .NET Framework, it is older server-side of application. I need to migrate it to the Windows Docker container on machine with Windows 10.
Beside that there will be running few IIS containers, that will interact with this WcfService but container to container communication is clear to me.
Then I have a client desktop application that must also be able to connect to the WcfService. In configuration file I specify Port and Hostname of wcfservice so I can connect.
This client may run on any machine within same LAN as WcfService container.
How should I construct command docker run <params> wcfservice and are there any other steps (firewall, Hyper-V settings,...) I need to do so that LAN can see this service and how can I retrieve hostname and port from this container?

Related

Equivalent of "host" network with docker-compose for containers running on windows

I'm using docker-compose on linux. In my compose-file I have network_mode: "host" for bunch of containers. This is convenient for my stack to able to access my containers as localhost:<port>.
Now I've had to run this on windows and it doesn't work. I've read this in the docs:
The host networking driver only works on Linux hosts, and is not
supported on Docker Desktop for Mac, Docker Desktop for Windows, or
Docker EE for Windows Server.
So.... anyways I have to access my container's exposed port on windows by some other means, as localhost:port as I on linux? Or do I HAVE to map them out to some random IP and access something like 3.70.0.1:port on windows?
To clarify this question and related issue. See comments on the question for details.
Indeed, simply specifying
ports: <host>:<container>
allows you to access your container/services as localhost:<host> from the host on linux/windows (likely mac too). That being said, specifying network_mode: host in your docker-compose.yaml service definition actually disables this on windows (and likely mac) systems.
A related issue I was having was that in some of my service, the IP address for communication between containers was of the type localhost:<container>. If you use network_mode: host, then indeed from both the host and container's perspective, the service run on localhost. However if you just use port mapping, then while the service run on localhost from the host's perspective, they then run on docker's private network from the service's perspective. So they will expect an IP address of the form <service_name>:<container_port> to communicate between containers.

WSL2 - Docker without Docker Desktop - cloud_sql_proxy does not work with VPN

So far I have worked/developed with Windows 10, Docker Desktop and WSL2. Now I had to remove Docker Desktop for licensing reasons and decided to run Docker natively in my WSL2 distro. This also works flawlessly. I can access my Docker applications in WSL from Windows.
For the data connections I use the cloud_sql_proxy from Google.
Again, no problems here. However, they occur as soon as I turn on the VPN. Then I can't connect to the database anymore. Everything else works!
The following:
VPN turned off. Connect to the DB via the cloud_sql container. Everything Okay
turn on VPN. DB connection remains established, but breaks down as soon as a reconnect is necessary.
VPN switched on. LOG in container: net/http: TLS handshake timeout
Using
gcr.io/cloudsql-docker/gce-proxy:1.31.2
Windows 10
Ubuntu-20.04
VPN L2TP (Windows nativ)
Using the cloud_sql_proxy service instead of the Docker container works. Can anyone help me with this? Why does it not work with the Docker container?

Network communication between Windows + WSL2 + Docker

I have a web app hosted in a Docker container and exposes port 5050 that is mapped to port 80 of the container.
The web app listens on 0.0.0.0:5050.
The Docker engine runs on WSL2.
Now when I open a browser on Windows and go to http://localhost:5050, everything works and I can see the web app.
But I don't understand how the request can reach the Docker container when I navigate to localhost on Windows.
Any ideas ?
The reason is that Docker for Windows uses a WSL2 backend, and is integrated with WSL distros.

What will be host value to connect for a Docker application with Docker database?

Have a Docker database mySql which has been setup like port 3308:3306, that mean internal docker port 3306 has been hosted by local host port 3308 and i am able to connect with this DB from my local machine and application by using port 3308 simply.
but if i run an application in Docker itself, what should be the value of below hostname and port to connect with Docker database.
jdbc:mysql://hostname:port/DBName?useSSL=false
I would recommend this kind of setup to the docker run command
Create a private bridge network.
docker network create --driver bridge privet-net
Now start your application and DB containers along with the following flag added.
--network private-net
On user-defined networks, containers can not only communicate by IP address but can also resolve a container name to an IP address. This capability is called automatic service discovery.
Read this for more details on Docker container networking.
Now you can use the following URL to access the database.
jdbc:mysql://<DB_Container_name>:port/DBName?useSSL=false
This approach might look complex, but its the recommended way. With this setup, your DB will be in a private network and cannot be accessed by other containers as well. This adds extra security to your database.

Connect to remote Docker Swarm from Windows

I would like to connect to a remote Docker Swarm (Ubuntu) from a Windows box.
In Linux it seams that you need to update the daemon.json file.
How do you achieve this in Windows?
Thanks!
The Docker engine has two parts, the daemon service (dockerd) that's running on your Ubuntu box, we'll call it the "server". Then the docker cli is what you can run from that server (docker) or from anything like your Windows machine (docker.exe). We'll call this the "client".
The client can talk to the server over two main ways, the socket, and a TCP port. The socket is usually reserved for local connections (SSH into the server and the docker client defaults to using the socket file to talk to the local server) or SSH tunnels, which are not something that works out of the box on Windows (maybe if you try the Windows Subsystem for Linux on Windows 10).
The other connection option is TCP, which isn't enabled on the server out of the box for security reasons. It has no authentication when enabled, so you'll want to use TLS to authenticate remotely, so Docker has steps for that. It's not a 3 min solution, so many look for an easier route to solve this problem.
The easier option for enabling TLS and the TCP port on the server is to use Docker Cloud with the "Bring Your Own Swarm" feature, which manages the certificates and security for you.

Resources