def contain(command, image_name, image_dir, container_id, container_dir,
cpu_shares, memory, memory_swap):
_setup_cpu_cgroup(container_id, cpu_shares)
# TODO: similarly to the CPU cgorup, add Memory cgroup support here
# setup memory -> memory.limit_in_bytes,
# memory_swap -> memory.memsw.limit_in_bytes if they are not None
linux.sethostname(container_id) # Change hostname to container_id
linux.mount(None, '/', None, linux.MS_PRIVATE | linux.MS_REC, None)
new_root = create_container_root(
image_name, image_dir, container_id, container_dir)
print('Created a new root fs for our container: {}'.format(new_root))
_create_mounts(new_root)
old_root = os.path.join(new_root, 'old_root')
os.makedirs(old_root)
linux.pivot_root(new_root, old_root)
os.chdir('/')
linux.umount2('/old_root', linux.MNT_DETACH) # umount old root
os.rmdir('/old_root') # rmdir the old_root dir
os.execvp(command[0], command)
评论列表
文章目录