Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
davidguidali opened this issue Mar 18, 2021 · 1 comment
Open

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

davidguidali opened this issue Mar 18, 2021 · 1 comment

Comments

@davidguidali
Copy link

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<string, string> options = new Dictionary<string, string>();
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?

@jterry75
Copy link
Contributor

It seems like in the JSON you need this under NetworksCreateParameters.IPAM.Config.Options. And the keys are Subnet and Gateway. The --Keys are just cmdline opts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants