dotnet / dotnet/Docker.DotNet

How to set static gateway and subnet when creating a network?

Open
#506 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2.4k
Forks
416
PR merge metrics
No merged PRs in 30d

Description

I am using docker for windows with windows containers.

Basically all I want to do is execute this command via the C# client (executing it in cmd works fine):

```
docker network create --driver=nat --subnet=10.123.174.0/23 --gateway=10.123.174.1 my_network
```

However, somehow I do not manage to set up the network properly. I use this small piece of code:

```
Dictionary options = new Dictionary();
options.Add("--gateway", "10.123.174.1");
options.Add("--subnet", "10.123.174.0/23");
await _client.Networks.CreateNetworkAsync(new NetworksCreateParameters { Driver = "nat", Name = "my_network", Options = options });
```

But the network still is created with another gateway than specified, putting my options only in the network "options" array:
```
[
{
"Name": "my_network",
"Id": "2bb2fabfa84518a2a11eff881c859bf324ce732c308a1d5a4d541c74870f5e70",
"Created": "2021-03-17T14:09:01.694993+01:00",
"Scope": "local",
"Driver": "nat",
"EnableIPv6": false,
"IPAM": {
"Driver": "windows",
"Options": null,
"Config": [
{
"Subnet": "172.29.96.0/20",
"Gateway": "172.29.96.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {
"--gateway": "10.123.174.1",
"--subnet": "10.123.174.0/23",
"com.docker.network.windowsshim.hnsid": "3065184F-EFAF-4537-AF64-F2CD373A3261"
},
"Labels": {}
}
]
```

I also tried to specify just "subnet" and "gateway" (without the "--") but the result was the same. What do I do wrong?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.