Add bind points for /dev/ and /etc/resolv.conf into the container when exec'ing
This commit is contained in:
@@ -1,13 +1,15 @@
|
|||||||
// +build linux
|
// + build linux
|
||||||
|
|
||||||
package child
|
package child
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||||
|
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||||
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
"github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,10 +27,15 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
syscall.Mount("", "/", "", syscall.MS_PRIVATE, "")
|
|
||||||
|
|
||||||
containerPath := container.RootFsDir(containerName)
|
containerPath := container.RootFsDir(containerName)
|
||||||
|
|
||||||
|
syscall.Mount("", "/", "", syscall.MS_PRIVATE, "")
|
||||||
|
syscall.Mount("/dev", path.Join(containerPath, "/dev"), "", syscall.MS_BIND, "")
|
||||||
|
|
||||||
|
if util.IsFile(path.Join(containerPath, "/etc/resolv.conf")) == true {
|
||||||
|
syscall.Mount("/etc/resolv.conf", path.Join(containerPath, "/etc/resolv.conf"), "", syscall.MS_BIND, "")
|
||||||
|
}
|
||||||
|
|
||||||
syscall.Chroot(containerPath)
|
syscall.Chroot(containerPath)
|
||||||
os.Chdir("/")
|
os.Chdir("/")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user