🐳 限制 CPU、内存使用

This commit is contained in:
Liang Ding 2019-05-17 18:20:36 +08:00
parent 04a2c8ed2f
commit 43a3ffe2a0
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
2 changed files with 2 additions and 2 deletions

View File

@ -51,7 +51,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
var cmd *exec.Cmd
if conf.Docker {
fileName := filepath.Base(filePath)
cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName)
cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "--cpus", "0.1", "--memory", "32m", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName)
} else {
cmd = exec.Command(filePath)
curDir := filepath.Dir(filePath)

View File

@ -52,7 +52,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
var cmd *exec.Cmd
if conf.Docker {
fileName := filepath.Base(filePath)
cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName)
cmd = exec.Command("timeout", "5", "docker", "run", "--rm", "--cpus", "0.1", "--memory", "32m", "-v", filePath+":/"+fileName, conf.DockerImageGo, "/"+fileName)
} else {
cmd = exec.Command(filePath)
curDir := filepath.Dir(filePath)