1
0
mirror of https://github.com/bingohuang/docker-labs.git synced 2025-07-14 01:57:32 +08:00

Memory limit (#26)

* Hardcode memory to 512mb

Fixes #21

* Add constants to define memory and disable OOM
This commit is contained in:
Marcos Nils 2016-11-13 17:09:44 +02:00 committed by GitHub
parent f49f0d8ce0
commit cdf1027e94

View File

@ -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, "")