From cdf1027e94d9933e287baba35209a06d6d403273 Mon Sep 17 00:00:00 2001 From: Marcos Nils Date: Sun, 13 Nov 2016 17:09:44 +0200 Subject: [PATCH] Memory limit (#26) * Hardcode memory to 512mb Fixes #21 * Add constants to define memory and disable OOM --- services/docker.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/services/docker.go b/services/docker.go index 701db4a..7dd238c 100644 --- a/services/docker.go +++ b/services/docker.go @@ -12,6 +12,12 @@ import ( var c *client.Client +const ( + Byte = 1 + Kilobyte = 1024 * Byte + Megabyte = 1024 * Kilobyte +) + func init() { var err error c, err = client.NewEnvClient() @@ -76,10 +82,11 @@ func ResizeExecConnection(execId string, ctx context.Context, cols, rows uint) e func CreateInstance(net string, dindImage string) (*Instance, error) { - var maximumPidLimit int64 - maximumPidLimit = 150 // Set a ulimit value to prevent misuse h := &container.HostConfig{NetworkMode: container.NetworkMode(net), Privileged: true} - h.Resources.PidsLimit = maximumPidLimit + h.Resources.PidsLimit = int64(150) + h.Resources.Memory = 512 * Megabyte + t := true + h.Resources.OomKillDisable = &t conf := &container.Config{Image: dindImage, Tty: true} container, err := c.ContainerCreate(context.Background(), conf, h, nil, "")