Docker for windows development environment setup

I am trying to figure out how to setup a development environment for developing multiple apis locally.

My development environment is as follows:

  • How to stop power shell script on error?
  • Assetss from wwwroot cannot be found on Docker Image
  • X509CertificateValidationMode not working in Linux?
  • Docker-compose up creates container but coudn't start it
  • Why GDB not stopped on break point?
  • Cannot connect to SQL Server from a Docker container
  • 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.

    SQL Server TCP IP Settings

    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

    network setup

  • How to run bower install inside a Dockerfile?
  • Clustering Docker containers behind load-balancers for HA
  • Docker run nanoserver not starting
  • gdb in docker container returns “ptrace: Operation not permitted.”
  • Pip is not installing packages on docker
  • Is it possible to deploy a docker hub publicly hosted image to Kubernetes Container Engine without uploading it to Containers Registery?
  • One Solution collect form web for “Docker for windows development environment setup”

    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.

    enter image description here

    The one thing I still cannot do is the host:container port mapping

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.