Skip to content

Commit af0a604

Browse files
Merge pull request #99 from Roblox/shm_size
Add support for shm_size.
2 parents 1f9cf42 + 10a29eb commit af0a604

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ More detailed instructions are in the [`example README.md`](https://github.com/R
106106
| **host_dns** | bool | no | Default (`true`). By default, a container launched using `containerd-driver` will use host `/etc/resolv.conf`. This is similar to [`docker behavior`](https://docs.docker.com/config/containers/container-networking/#dns-services). However, if you don't want to use host DNS, you can turn off this flag by setting `host_dns=false`. |
107107
| **seccomp** | bool | no | Enable default seccomp profile. List of [`allowed syscalls`](https://github.com/containerd/containerd/blob/master/contrib/seccomp/seccomp_default.go#L51-L395). |
108108
| **seccomp_profile** | string | no | Path to custom seccomp profile. `seccomp` must be set to `true` in order to use `seccomp_profile`. The default `docker` seccomp profile found [`here`](https://github.com/moby/moby/blob/master/profiles/seccomp/default.json) can be used as a reference, and modified to create a custom seccomp profile. |
109+
| **shm_size** | string | no | Size of /dev/shm e.g. "128M" if you want 128 MB of /dev/shm. |
109110
| **sysctl** | map[string]string | no | A key-value map of sysctl configurations to set to the containers on start. |
110111
| **readonly_rootfs** | bool | no | Container root filesystem will be read-only. |
111112
| **host_network** | bool | no | Enable host network. This is equivalent to `--net=host` in docker. |

containerd/containerd.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/containerd/containerd/oci"
3131
refdocker "github.com/containerd/containerd/reference/docker"
3232
remotesdocker "github.com/containerd/containerd/remotes/docker"
33+
"github.com/docker/go-units"
3334
specs "github.com/opencontainers/runtime-spec/specs-go"
3435
)
3536

@@ -164,6 +165,15 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
164165
}
165166
}
166167

168+
// Size of /dev/shm
169+
if len(config.ShmSize) > 0 {
170+
shmBytes, err := units.RAMInBytes(config.ShmSize)
171+
if err != nil {
172+
return nil, fmt.Errorf("Error in setting shm_size: %v", err)
173+
}
174+
opts = append(opts, oci.WithDevShmSize(shmBytes/1024))
175+
}
176+
167177
// Set sysctls
168178
if len(config.Sysctl) > 0 {
169179
opts = append(opts, WithSysctls(config.Sysctl))

containerd/driver.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ var (
118118
"entrypoint": hclspec.NewAttr("entrypoint", "list(string)", false),
119119
"seccomp": hclspec.NewAttr("seccomp", "bool", false),
120120
"seccomp_profile": hclspec.NewAttr("seccomp_profile", "string", false),
121+
"shm_size": hclspec.NewAttr("shm_size", "string", false),
121122
"sysctl": hclspec.NewAttr("sysctl", "list(map(string))", false),
122123
"readonly_rootfs": hclspec.NewAttr("readonly_rootfs", "bool", false),
123124
"host_network": hclspec.NewAttr("host_network", "bool", false),
@@ -183,6 +184,7 @@ type TaskConfig struct {
183184
Devices []string `codec:"devices"`
184185
Seccomp bool `codec:"seccomp"`
185186
SeccompProfile string `codec:"seccomp_profile"`
187+
ShmSize string `codec:"shm_size"`
186188
Sysctl hclutils.MapStrStr `codec:"sysctl"`
187189
Privileged bool `codec:"privileged"`
188190
PidsLimit int64 `codec:"pids_limit"`

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ require (
1414
github.com/docker/docker v17.12.0-ce-rc1.0.20200330121334-7f8b4b621b5d+incompatible
1515
github.com/docker/docker-credential-helpers v0.6.3 // indirect
1616
github.com/docker/go-metrics v0.0.1 // indirect
17+
github.com/docker/go-units v0.4.0
1718
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
1819
github.com/gogo/googleapis v1.4.0 // indirect
1920
github.com/hashicorp/consul-template v0.25.1

0 commit comments

Comments
 (0)