Docker for windows development environment setup - c#

I am trying to figure out how to setup a development environment for developing multiple apis locally.
My development environment is as follows:
Host Machine: 10.10.4.19
SQL Server 2016 Express Installed on the host listening at 10.10.4.19,1433 which I can connect to locally from the host and from other PCs on the network.
Docker for windows stable version, installed and developing netcore webapis which get containerized and run locally which I want to connect to the SQL Server Instance on the host.
Ideally each container would have a static IP in some NAT network, however I have been unable to get static IPs working for the default NAT network setup with docker for windows.
I have tried setting up a transparent network, however this probably won't work as I don't really want these on network. I would like them only to be accessible by the host, or through some port mapping by the host IP through the docker run -p command.
I have the containers running and working (except for static ip addresses) however I cannot access the host. I can ping (what I am assuming is) the host at the gateway IP address found in the container, but I can't seem to access any services running on the host.
From within the container I can ping other PCs in the network (IE 10.10.4.22) and have internet access, but for some reason I cannot ping the host at 10.10.4.19. I get the Request timed out.
So the question I am asking is, how can i setup a NAT network with internet access where containers can talk to the host and other containers and the host can talk to all containers too. And ideally I could setup static IPs for each service where I could setup nginx or some other reverse proxy on the host to help proxy requests to each container.
I have tried creating a separate NAT using docker network create -d NAT mynat but it tells me the object already exists.
I have tried accessing the host's SQL instance by the 10.10.4.19 ip address and the 172.20.xxx.1 address defined on the virtual NIC however none of them will connect to the SQL instance or any website/api I have running on the host. The containers however can access other PC's websites/apis on the network. Just not the host.
So I guess I am asking if it is even possible to access the host's services from inside a container too?
A lot of the documentation I have found is based on linux and I'm not sure if it can be used the same or not
Any direction anyone can give will be greatly appreciated.
EDIT:
After playing all night with the docker networks, I was able to replace the default docker NAT network with my own so I could specify static IP address.
What I did for that was add "bridge: "none" to the daemon.json file located at C:\ProgramData\Docker\config. Which made it so the default NAT network isn't created by default
Then I ran the following commands in an admin powershell to create my own NAT network
PS C:\WINDOWS\system32> stop-service com.docker.service
PS C:\WINDOWS\system32> stop-service hns
PS C:\WINDOWS\system32> del 'C:\ProgramData\Microsoft\Windows\HNS\HNS.data'
PS C:\WINDOWS\system32> Get-ContainerNetwork | Remove-ContainerNetwork
PS C:\WINDOWS\system32> Get-NetNat | Remove-NetNat
PS C:\WINDOWS\system32> start-service hns
PS C:\WINDOWS\system32> start-service com.docker.service
PS C:\WINDOWS\system32> docker network create -d nat --subnet=192.168.1.0/24 --gateway=192.168.1.1 mynat
d0d31ecf39ec6cada948c3158b176e9a67d7e0ba6458208d9c91b240587c0763
I am then able to start my containers with the following command
docker run -itd --net=mynat --ip=192.168.1.25 --rm <containername>
However: I am still unable to access the SQL Server Express instance on the host machine. I thought I would be able to access it at 192.168.1.1,1433\SQL2016 or 10.10.4.19\SQL2016 however I get the error: provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified for both.
Pinging 192.168.1.1 does return results, however pinging 10.10.4.19 returns Request timed out.
I have set a static IP of 192.168.1.1 on the virtual NIC adapter and that didn't seem to help anything. Hopefully someone knows how to access the host from within a container. Thanks!
EDIT2:
I am able to hit an api running on the host now. To be honest I am not sure what changed. But i can now hit a service at http://192.168.1.1/api running on the host from the within the container.
NOTE: That the port binding doesn't seem to work though going to the static IP setup on the container. You can only hit the service on the EXPOSE port in the dockerfile and running the docker command with -p 5600:9606 doesn't expose on 5600 it is still exposed only on 9606. calling 192.168.1.25:9606 works but localhost:5600 does not
However I am still unable to connect to the SQL Server Express instance on the 192.168.1.1 IP. I have tried adding the 192.168.1.1 ip to the SQL Server bindings but that doesn't seem to work.
I can connect from the host at 10.10.4.19,1433\SQL2016 but cannot connect at 192.168.1.1,1433\SQL2016 so I am assuming that is the issue at hand here. Windows Firewall is disabled.
I have set the virtual NAT NIC to use the static ip 192.168.1.1 also but still cannot connect to the SQL Server instance at 192.168.1.1,1433\SQL2016

The last thing i had to do was enable both ipv4 and ipv6 (as ipv6 was used for some of the authentication checks I guess) on the host server for sql server express 2016. And added firewall rules.
Hopefully this will help someone else get setup for local development and single server docker deployments.
The one thing I still cannot do is the host:container port mapping

Related

No such host is known —> System.Net.Http.HttpRequestException:

I am developing bot solution, in which I am making REST call to get some details from other server.
In local host my code is working fine, but after publishing the code in Azure I am getting the below error:
System.Net.WebException: No such host is known No such host is known —> System.Net.Http.HttpRequestException: No such host is known —> System.Net.Sockets.SocketException: No such host is known
I am using HttpWebRequest option.
May I know what could be the reason?
I'm not sure the solution below will work for you but it looks like the solution is worth to be checked out. Here is an answer that may have useful information. Take a look at this answer and check your solution accordingly:
The problem description:
I deployed a .NET Windows Service on Azure Virtual Machine running
Windows Server with an opened port that allow me to connect to it,
this service is like a server using socket. The problem is that when I
try to connect from my PC to that hosted server it doesn't work and I
get this exception: System.Net.Sockets.SocketException: 'No such host
is known'. The port is opened and visible from my PC. Can someone tell
me why I get that exception? If I run locally all works ok.
The answer:
The Exception seems to be a DNS issue. I am not familiar with C#, from
networking, you could check the followings on your side:
Windows service is running and the port is listening on the Azure VM.
The port is allowed for outbound traffic from your PC and Inbound
traffic on your Azure VM. Check the VM firewall settings on both sides
between your PC and Azure VM. Also, you could check the NSG settings
follow this. You could use telnet vmpublicIP port on your PC CMD to
verify network connectivity.
Verify your PC can resolve the address of the hosted server if you connect
it via its DNS name. You could use the NSlookup or DIG to verify this.
If it's DNS issue, you also could add a line in hosts file (located in
%WINDIR%\system32\drivers\etc on windows) mapping the hosted server's
IP to a name. Hope this helps.
.NET Service System.Net.Sockets.SocketException: 'No such host is known'

.NET Service System.Net.Sockets.SocketException: 'No such host is known'

I deployed a .NET Windows Service on Azure Virtual Machine running Windows Server with an opened port that allow me to connect to it, this service is like a server using socket. The problem is that when I try to connect from my PC to that hosted server it doesn't work and I get this exception: System.Net.Sockets.SocketException: 'No such host is known'. The port is opened and visible from my PC. Can someone tell me why I get that exception? If I run locally all works ok.
The Exception seems to be a DNS issue. I am not familiar with C#, from networking, you could check the followings on your side:
Windows service is running and the port is listening on the Azure VM.
The port is allowed for outbound traffic from your PC and Inbound traffic on your Azure VM. Check the VM firewall settings on both sides between your PC and Azure VM. Also, you could check the NSG settings follow this. You could use telnet vmpublicIP port on your PC CMD to verify network connectivity.
Verify your PC can resolve the address of hosted server if you connect it via its DNS name. You could use the NSlookup or DIG to verify this. If it's DNS issue, you also could add a line in hosts file (located in %WINDIR%\system32\drivers\etc on windows) mapping the hosted server's IP to a name.
Hope this helps.

Unabled to access locally hosted wcf service over the internet

Running wcf service on local machine and trying to connect from another machine by public IP address on specified port not LAN internal IP.
basically I wanted to make chat application without including any central server. client machine would be treat as a server like torrent.
You have to forward the port from your router to the computer on your local network. That's because the router is in between your computer and the Internet, and so your router is actually the one with the Public IP.
There is a site that has good guides for forwarding ports on many different router models. Also check your router's manual if you still have it.

SQL Server c# connection

So Im running a Sql Server 2012 in a virtual machine on my computer and I want to be able to connect on it with the SqlConnection on Visual Studio, but I have no idea what to put on the servername parameter.
I dont know if I have to put the vm ipaddress or the machine address "WIN-NIJ53etc\SQLEXPRESS"
UPDATED:
FOR MIGRATING BETWEEN SQL CE AND SQL SERVER: Please take a look at this instruction here.
You should follow these steps:
1- Set the virtual machine to have a physical IP address.
For configuring network on Microsoft Virtual PC: http://support.microsoft.com/kb/833134
2- Be sure that you can see the VM with a static IP address. (ping is a good idea for checking that, but don't forget to turn off the firewall on the target machine, I mean the machine you wanna ping. There is no need for the server to see the client, so check that your client (in this case your VM) can ping the server IP address like "ping 192.168.10.1 -t")
3- Use Configuration Manager (All Programs\Microsoft SQL Server\Configuration Tools) and set SQL port and visibility over network.
Reference: http://msdn.microsoft.com/en-us/library/ms189083(v=sql.105).aspx
4- Restart the SQL server.
5- Be sure that "SQL Server Browser" service is started. (incase you wanna use the instance name to access the SQL server)
6- Config the firewall on the host machine (machine that has SQL engine) and add the port you specified in the Configuration Manager to TCP Inbound rules.
Take a look at here: http://www.tavislovell.com/post/How-to-configure-Windows-Firewall-to-allow-access-to-SQL-Server.aspx
BUT be advised that you should set the port specified in the Configuration Manager (default is 1433 but sometimes it's dynamic and you should set it again)
7- After you set the port and network visibility, you should change the "Server" value in the connection string to this format "IPAddress, PORT" like "192.168.10.50, 1433" (When you specify the port, there is no need to set the instance name like this "192.168.10.50\SQLEXPRESS")
Hope it helps
Ahh the joys of SQL Server Installation setup.
Make sure you have:
Network communication between the VM and the client computer (ping will work)
The SQL Server Service configured to start automatically or that it is started
The service configured to use TCP (if you don't want to use Named Pipes)
Either the SQL Server Browser enabled and started or that a static port is configured (1433 or similar)
The firewall rules configured to allow 1433 (or the port you have chosen) and 1434 (if you are using browser)
The connection string using the proper format Computer Name\Instance (to use browser) or Computer Name,port (if you are using a static port
There is a good tutorial on MSDN that may prove helpful. With specific regard to the Server Name/IP question, it doesn't matter so long as the client computer can resolve it. If you are testing, "IP,Port" is the most reliable (E.g. 10.10.10.100,1433) as it does not depend on NetBIOS, DNS nor the SQL Browser service.

c# socket server - deploying, starting, stopping

I'm a little confused when it comes to socket servers in terms of deploying it online.
Running locally is fine as most tutorials get you to make a server application and a client application which I can execute. Done all that for awhile now and I'm happy with it but now I want to try it using a web host.
How would I deploy the socket server to my web host and then run the server? do I just upload the program to the server and run www.mywebpage.com/mysocketserver (assuming the program is called mysocketserver.exe)
may sound like a stupid question but I'm having one of those brain dead moments.
[Edit]
Great answers guys thank you. Shame I can only mark one as the answer.
Most hosting services are website related: you upload your website to their server and the host takes care of provisioning the application.
However you haven't written a website that is served by a web server, but a socket server, which is more akin to the web server itself that runs a website.
As a result you will need a host that will allow you to install and run applications, such as a Virtual Private Server service, rent a physical server or use a cloud service such as Amazon EC2.
You usually Remote Desktop or SSH into the server you are renting (or own) to upload and start the application either as a normal application, a Service or a Daemon.
Once you have installed your socket server on the host server and started the application running you should be able to contact your service using the IP address for your server and the port that you are running your socket server on.
For example, if your ip address is 10.0.0.1 and you've written your socket server to listen on port 1234, you should be able to contact your service at address 10.0.0.1:1234.
Take into account firewalls allowing access to that port.
You will also then be able to use a DNS service such as DynDns to assign a domain name to that ip address.
You can't do that unless your socket server is using HTTP as a protocol.
You are using a port for your server, right? The ports are used to identify which application to talk with.
When you browse the web using "http://something" you really say let me get the stuff which can be found on the IP 1.2.3.4 (DNS lookup) using port 80 (which is registered for HTTP). You don't have to specify the port in the browser since all browsers know that HTTP uses port 80.
So what you are really should do is to put the socket server on your host and tell your customers/users that they can connect to your socket server at port XXX on host "www.mywebpage.com".
If you've built a client you'll just hard code the port in it or specify the default port automatically.
The problem in the Internet is the routing/name translation, so that mywebpage gets translated into the correct IP address.
Either your webserver needs a fixed public IP address or you need to use a service like dynds which will dynamically map your changing IP address to the static name.

Categories

Resources