CreateContainer creates a sysbox-runc container.
(ctx context.Context, client Client, conf *ContainerConfig)
| 42 | |
| 43 | // CreateContainer creates a sysbox-runc container. |
| 44 | func CreateContainer(ctx context.Context, client Client, conf *ContainerConfig) (string, error) { |
| 45 | host := &container.HostConfig{ |
| 46 | Runtime: runtime, |
| 47 | AutoRemove: true, |
| 48 | Resources: container.Resources{ |
| 49 | Devices: conf.Devices, |
| 50 | // Set resources for the inner container. |
| 51 | // This is important for processes inside the container to know what they |
| 52 | // have to work with. |
| 53 | // TODO: Sysbox does not copy cpu.cfs_{period,quota}_us into syscont-cgroup-root cgroup. |
| 54 | // These will not be visible inside the child container. |
| 55 | // See: https://github.com/nestybox/sysbox/issues/582 |
| 56 | CPUPeriod: int64(DefaultCPUPeriod), |
| 57 | CPUQuota: conf.CPUs * int64(DefaultCPUPeriod), |
| 58 | Memory: conf.MemoryLimit, |
| 59 | }, |
| 60 | ExtraHosts: []string{"host.docker.internal:host-gateway"}, |
| 61 | Binds: generateBindMounts(conf.Mounts), |
| 62 | } |
| 63 | |
| 64 | entrypoint := []string{"sleep", "infinity"} |
| 65 | if conf.HasInit { |
| 66 | entrypoint = []string{"/sbin/init"} |
| 67 | } |
| 68 | |
| 69 | if conf.Hostname == "" { |
| 70 | conf.Hostname = conf.Name |
| 71 | } |
| 72 | |
| 73 | cnt := &container.Config{ |
| 74 | Image: conf.Image, |
| 75 | Entrypoint: entrypoint, |
| 76 | Cmd: []string{}, |
| 77 | Env: conf.Envs, |
| 78 | Hostname: conf.Hostname, |
| 79 | WorkingDir: conf.WorkingDir, |
| 80 | Tty: false, |
| 81 | User: "root", |
| 82 | } |
| 83 | |
| 84 | c, err := client.ContainerCreate(ctx, cnt, host, nil, nil, conf.Name) |
| 85 | if err != nil { |
| 86 | return "", xerrors.Errorf("create container: %w", err) |
| 87 | } |
| 88 | return c.ID, nil |
| 89 | } |
| 90 | |
| 91 | type BootstrapConfig struct { |
| 92 | ContainerID string |
no test coverage detected