Skip to content

Commit 792a0cb

Browse files
committed
support running container with network id
Signed-off-by: fahed dorgaa <[email protected]>
1 parent 2becba6 commit 792a0cb

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Diff for: cmd/nerdctl/container_run_network_linux_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,20 @@ func TestRunInternetConnectivity(t *testing.T) {
4242
type testCase struct {
4343
args []string
4444
}
45+
customNetID := base.InspectNetwork(customNet).ID
4546
testCases := []testCase{
4647
{
4748
args: []string{"--net", "bridge"},
4849
},
4950
{
5051
args: []string{"--net", customNet},
5152
},
53+
{
54+
args: []string{"--net", customNetID},
55+
},
56+
{
57+
args: []string{"--net", customNetID[:12]},
58+
},
5259
{
5360
args: []string{"--net", "host"},
5461
},

Diff for: pkg/netutil/netutil.go

+8
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ func (e *CNIEnv) NetworkMap() (map[string]*NetworkConfig, error) { //nolint:revi
165165
log.L.Warnf("duplicate network name %q, %#v will get superseded by %#v", n.Name, original, n)
166166
}
167167
m[n.Name] = n
168+
if n.NerdctlID != nil {
169+
id := *n.NerdctlID
170+
m[id] = n
171+
if len(id) > 12 {
172+
id = id[:12]
173+
m[id] = n
174+
}
175+
}
168176
}
169177
return m, nil
170178
}

0 commit comments

Comments
 (0)