I have created two docker container on windows (running windows mode).
MSSQL-Server and an IIS container.
If I like to connect one of this container with 127.0.0.1:PORT it is not working. If I get the IP-Address with docker inspect and use this IP-Address it is working. (SQL Managment Studio accepts container_id as well)
Someone wrote that a connection on localhost is not working due to a bug in Windows…
So I have created my own network and set a static ip for my containers.
docker network create -d nat --subnet=192.0.0.0/24 --gateway=192.0.0.1 dockernet
docker run -p 8000:8000 -v "C:\Docker\iis:C:\inetpub" --net dockernet --ip 192.0.0.1 --name iis -d microsoft/iis
Everything is working fine so far.
Now I am able to stop and start the container as often as I want. IP stays the same.
When I restart window I am facing the problem that my containers won’t start anymore.
docker start mssql
tells me that my network with ID xxxxxxx is not found anymore.
Error response from daemon: network 9bb980abe928bd0c0a017fac3790944796bcb8ea544700892578c9304d2753e8 not found Error: failed to start containers: mssql
To get rid of this error I have to call
docker network connect dockernet mssql
Now I can start my container again with docker start, but now everytime I start and stop I will get a random IP.
I don’t like to start with docker run, because this will mess up all my databases and I need to attach them again. And I don’t like to add my dockerfile everytime I added a new database.
So my qustion is: How can I have a static ip, even after rebbot windows?