Docker Community Forums

Share and learn in the Docker community.

Static IP not working after reboot

(Pfloosy) #1

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 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= --gateway= dockernet

docker run -p 8000:8000 -v "C:\Docker\iis:C:\inetpub" --net dockernet --ip --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?


(Pfloosy) #2

Ok… I have found a solution by my self and like to share it with you:

Create a transparent network:

docker network create -d transparent --subnet= --gateway= mynet

Create a container (e.g. mssql-server)

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=Secret" --net mynet --ip -p 1433:1433 -v "C:\Docker\mssql-server:C:\db" --name mssql -d microsoft/mssql-server-windows-developer

… Container is running now.

If you restart the docker service or the entire PC the network_id will change.
When you try to start your container again

docker start mssql

You’ll get this error message

Error response from daemon: network c936575d156780bcf45ca43be09db27ec2a6ca0ac8fc65092b58090bfa7212c2 not found
Error: failed to start containers: mssql

… So here is the trick

Reconnect to the network

docker network connect --ip mynet mssql 

Start the container

docker start mssql

Check IP-Address

docker inspect -f "{{ .NetworkSettings.Networks.dockernet.IPAddress }}" mssql