Documentation ¶
Index ¶
- Constants
- func Commit(containerId, imageName string) error
- func DeleteInfo(containerId string) error
- func DeleteWorkSpace(volume, containerId string) error
- func Exec(containerId string, cmdArray []string) error
- func Log(containerId string) error
- func NewParentProcess(tty bool, volume, containerId, imageName string, envSlice []string) (*exec.Cmd, *os.File, error)
- func NewWorkSpace(volume, imageName, containerId string) error
- func RecordInfo(containerPid int, commandArray []string, ...) error
- func Remove(id string) error
- func RunContainerInitProcess() error
- func Stop(containerId string) error
- type Info
Constants ¶
const ( RUNNING = "running" STOP = "stopped" Exit = "exited" InfoLoc = "/var/run/mydocker/" InfoLocFormat = InfoLoc + "%s/" ConfigName = "config.json" IDLength = 10 LogFile = "container.log" )
const ( EnvExecPid = "mydocker_pid" EnvExecCmd = "mydocker_cmd" )
nsenter里的C代码里已经出现mydocker_pid和mydocker_cmd这两个Key,主要是为了控制是否执行C代码里面的setns.
const (
RootUrl = "/root/"
)
容器相关目录
Variables ¶
This section is empty.
Functions ¶
func DeleteWorkSpace ¶
DeleteWorkSpace 删除overlayFs当容器退出
和创建相反 1)有volume则卸载volume 2)卸载merged目录 3)卸载upper、worker层 4)移除该容器的overlayFs目录
func NewParentProcess ¶
func NewParentProcess(tty bool, volume, containerId, imageName string, envSlice []string) (*exec.Cmd, *os.File, error)
NewParentProcess 启动一个新进程
这里是父进程,也就是当前进程执行的内容。 1.这里的/proc/self/exe调用中,/proc/self/ 指的是当前运行进程自己的环境,exec 其实就是自己调用了自己,使用这种方式对创建出来的进程进行初始化 2.后面的args是参数,其中init是传递给本进程的第一个参数,在本例中,其实就是会去调用initCommand去初始化进程的一些环境和资源 3.下面的clone参数就是去fork出来一个新进程,并且使用了namespace隔离新创建的进程和外部环境。 4.如果用户指定了-it参数,就需要把当前进程的输入输出导入到标准输入输出上
func NewWorkSpace ¶
NewWorkSpace create an overlays filesystem as container root workspace
1)创建lower层 2)创建upper、worker层 3)创建merged目录并挂载overlayFS 4)如果有指定volume则挂载volume
func RecordInfo ¶
func RecordInfo(containerPid int, commandArray []string, containerName, containerId, volume string) error
RecordInfo 记录容器相关信息
func RunContainerInitProcess ¶
func RunContainerInitProcess() error
RunContainerInitProcess 启动容器的init进程
这里的init函数是在容器内部执行的,也就是说,代码执行到这里后,容器所在的进程其实就已经创建出来了, 这是本容器执行的第一个进程。 使用mount先去挂载proc文件系统,以便后面通过ps等系统命令去查看当前进程资源的情况。
Types ¶
type Info ¶
type Info struct { Pid string `json:"pid"` // 容器的init进程在宿主机上的 PID Id string `json:"id"` // 容器Id Name string `json:"name"` // 容器名 Command string `json:"command"` // 容器内init运行命令 CreatedTime string `json:"createTime"` // 创建时间 Status string `json:"status"` // 容器的状态 Volume string `json:"volume"` // 挂载的数据卷 PortMapping []string `json:"portMapping"` // 端口映射 }