Skip to content

Commit 4a39563

Browse files
committed
oci-hook: add /usr/sbin:/sbin to PATH for iptables
The directory of `iptables` is often missing in the default `$PATH`. Fix issue 1536 Thanks to jeffrson for testing. Signed-off-by: Akihiro Suda <[email protected]>
1 parent 4af3a5d commit 4a39563

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pkg/cmd/container/create.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ func withNerdctlOCIHook(cmd string, args []string) (oci.SpecOpts, error) {
540540
}
541541

542542
args = append([]string{cmd}, append(args, "internal", "oci-hook")...)
543+
// sbin is appended for iptables https://github.com/containerd/nerdctl/discussions/1536
544+
env := append(os.Environ(), "PATH="+os.Getenv("PATH")+":/usr/sbin:/sbin")
543545
return func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error {
544546
if s.Hooks == nil {
545547
s.Hooks = &specs.Hooks{}
@@ -548,14 +550,14 @@ func withNerdctlOCIHook(cmd string, args []string) (oci.SpecOpts, error) {
548550
s.Hooks.CreateRuntime = append(s.Hooks.CreateRuntime, specs.Hook{
549551
Path: cmd,
550552
Args: crArgs,
551-
Env: os.Environ(),
553+
Env: env,
552554
})
553555
argsCopy := append([]string(nil), args...)
554556
psArgs := append(argsCopy, "postStop")
555557
s.Hooks.Poststop = append(s.Hooks.Poststop, specs.Hook{
556558
Path: cmd,
557559
Args: psArgs,
558-
Env: os.Environ(),
560+
Env: env,
559561
})
560562
return nil
561563
}, nil

0 commit comments

Comments
 (0)