Last active
April 29, 2019 01:58
-
-
Save skanehira/cefae446112a4234d5cfbd55756c1675 to your computer and use it in GitHub Desktop.
make a simple container
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"os/exec" | |
"syscall" | |
) | |
func must(err error) { | |
if err != nil { | |
panic(err) | |
} | |
} | |
func main() { | |
// need to make rootfs dir from linux OS file system | |
// bellow is a sample to make rootfs dir from alpine | |
// $ docker pull alpine | |
// $ docker create --name alpine alpine | |
// $ docker export alpine > alpine.tar | |
// $ docker rm alpine | |
// $ mkdir rootfs | |
must(syscall.Chroot("./rootfs")) | |
must(syscall.Chdir("/")) | |
cmd := exec.Command("/bin/sh") | |
cmd.Stdin = os.Stdin | |
cmd.Stdout = os.Stdout | |
cmd.Stderr = os.Stderr | |
cmd.SysProcAttr = &syscall.SysProcAttr{ | |
Cloneflags: syscall.CLONE_NEWPID | syscall.CLONE_NEWUTS, | |
} | |
must(cmd.Run()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment