mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-15 02:37:27 +08:00
Memory limit (#26)
* Hardcode memory to 512mb Fixes #21 * Add constants to define memory and disable OOM
This commit is contained in:
parent
f49f0d8ce0
commit
cdf1027e94
@ -12,6 +12,12 @@ import (
|
|||||||
|
|
||||||
var c *client.Client
|
var c *client.Client
|
||||||
|
|
||||||
|
const (
|
||||||
|
Byte = 1
|
||||||
|
Kilobyte = 1024 * Byte
|
||||||
|
Megabyte = 1024 * Kilobyte
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
c, err = client.NewEnvClient()
|
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) {
|
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 := &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}
|
conf := &container.Config{Image: dindImage, Tty: true}
|
||||||
container, err := c.ContainerCreate(context.Background(), conf, h, nil, "")
|
container, err := c.ContainerCreate(context.Background(), conf, h, nil, "")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user