Support nerdctl network connect and network disconnect

Open
#5,355 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
go
Domain
cli, networking

Research direction

Read docs/command-reference.md, #3867, and applyNetworkSettings in pkg/ocihook to understand current network setup and stored results. Trace how container labels and the hosts store are updated, then check how CNI add and del operate in a running container's network namespace. Done means nerdctl network connect and disconnect work for rootful containers and network membership persists across restart; the issue asks for feedback on the approach, so confirm the intended scope before implementing.

Written by the indexing model from the issue text.

Description

What is the problem you're trying to solve

docker network connect and docker network disconnect are on the unimplemented list in docs/command-reference.md and in #3867. A running container can only get its networks at nerdctl run time. Adding or removing one later means recreating the container, which is a problem for stateful containers and for tooling that expects Docker's behavior.

Describe the solution you'd like

nerdctl network connect NETWORK CONTAINER and nerdctl network disconnect NETWORK CONTAINER for a running container, starting with rootful mode.

What I understand of the current code, please correct me:

  • The OCI hook runs one CNI setup for the whole list of networks when the container starts (applyNetworkSettings in pkg/ocihook), and records the results in the hosts store.
  • So connect would need to run a CNI add for one network on the running container's netns, give it the next free ethN, and update the hosts store so DNS and /etc/hosts for the other containers see it.
  • Disconnect is the reverse, with a CNI del.
  • The set of networks has to be written back to the container's labels, so a restart sets the same networks up again.

I'd start with --alias and leave --ip and --ip6 for later. Is this a direction you want, and is there a reason it hasn't been done that I'm missing, such as how the interface names are chosen or the rootless case?

Additional context

I haven't started on it, and I wanted to check the approach before writing code.

Dominant language
Go
Stars
10.5k
Forks
853
Avg merge
6d 14h
Merged PRs (30d)
38

Getting set up

  • Ships a Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from containerd/nerdctl

All issues in containerd/nerdctl

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.