pibigstar / go-docker Goto Github PK
View Code? Open in Web Editor NEW用go写一个docker
用go写一个docker
我使用的是 go 1.13.8 centos 7.9
demo 代码:
package main
import (
"log"
"os"
"os/exec"
"syscall"
)
func main() {
cmd := exec.Command("sh")
cmd.SysProcAttr = &syscall.SysProcAttr{
// 隔离 uts,ipc,pid,mount,user,network
Cloneflags: syscall.CLONE_NEWUTS |
syscall.CLONE_NEWIPC |
syscall.CLONE_NEWPID |
syscall.CLONE_NEWNS |
syscall.CLONE_NEWUSER |
syscall.CLONE_NEWNET,
// 设置容器的UID和GID
UidMappings: []syscall.SysProcIDMap{
{
// 容器的UID
ContainerID: 1,
// 宿主机的UID
HostID: 0,
Size: 1,
},
},
GidMappings: []syscall.SysProcIDMap{
{
// 容器的GID
ContainerID: 1,
// 宿主机的GID
HostID: 0,
Size: 1,
},
},
}
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatal(err)
}
}
我使用的是root用户运行的代码
$ go run .
2020/12/24 10:26:26 fork/exec /usr/bin/sh: invalid argument
exit status 1
这里出错是什么一个什么原因呢?对linux不太熟悉。
希望大佬解答解答,感谢!!!
/container/process.go
修正为
// 指定容器初始化后的工作目录
// cmd.Dir = common.MntPath
cmd.Dir = path.Join(common.MntPath, containerName)
/container/workspace.go
如果提示xino问题,则需要使用下列方式
//! mount -t aufs -o noxino,dirs=/root/writeLayer/test:/root/busybox none /root/mnt/test
dirs := fmt.Sprintf("noxino,dirs=%s:%s", writeLayPath, imagePath)
cmd := exec.Command("mount", "-t", "aufs", "-o", dirs, "none", mntPath)
大佬,我是个go小白。请问这个手写docker,我应该从何入手呢,老哥是自己纯手写的吗?有看视频教程之类的吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.