mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-14 01:57:32 +08:00
Allow dind image to be overriden.
- improve readme - mention pre-pulling dind image. - read env variable once in init() method
This commit is contained in:
parent
11749c4902
commit
7df6bacee5
@ -9,6 +9,8 @@ A live version is available at: http://play-with-docker.com/
|
||||
|
||||
## Installation
|
||||
|
||||
Start the Docker daemon on your machine and run `docker pull docker:1.12.2-rc2-dind`.
|
||||
|
||||
1) Install go 1.7.1 with `brew` on Mac or through a package manager.
|
||||
|
||||
2) `go get`
|
||||
@ -21,5 +23,7 @@ A live version is available at: http://play-with-docker.com/
|
||||
|
||||
Notes:
|
||||
|
||||
There is a hard-coded limit to 5 Docker playgrounds per session. After 1 hour sessions are deleted.
|
||||
* There is a hard-coded limit to 5 Docker playgrounds per session. After 1 hour sessions are deleted.
|
||||
* If you want to override the DIND version or image then set the environmental variable i.e.
|
||||
`DIND_IMAGE=docker:dind`
|
||||
|
||||
|
@ -2,7 +2,6 @@ package services
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
ptypes "github.com/franela/play-with-docker/types"
|
||||
@ -75,18 +74,13 @@ func AttachExecConnection(execId string, ctx context.Context) (*types.HijackedRe
|
||||
return &conn, nil
|
||||
}
|
||||
|
||||
func CreateInstance(net string) (*ptypes.Instance, error) {
|
||||
func CreateInstance(net string, dindImage string) (*ptypes.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
|
||||
|
||||
dindImage := os.Getenv("DIND_IMAGE")
|
||||
if len(dindImage) == 0 {
|
||||
dindImage = "docker:1.12.2-rc2-dind"
|
||||
}
|
||||
|
||||
conf := &container.Config{Image: dindImage}
|
||||
container, err := c.ContainerCreate(context.Background(), conf, h, nil, "")
|
||||
|
||||
|
@ -1,19 +1,37 @@
|
||||
package services
|
||||
|
||||
import "github.com/franela/play-with-docker/types"
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/franela/play-with-docker/types"
|
||||
)
|
||||
|
||||
var instances map[string]map[string]*types.Instance
|
||||
|
||||
var dindImage string
|
||||
var defaultDindImageName string
|
||||
|
||||
func init() {
|
||||
instances = make(map[string]map[string]*types.Instance)
|
||||
dindImage = getDindImageName()
|
||||
}
|
||||
|
||||
func getDindImageName() string {
|
||||
dindImage := os.Getenv("DIND_IMAGE")
|
||||
defaultDindImageName = "docker:1.12.2-rc2-dind"
|
||||
if len(dindImage) == 0 {
|
||||
dindImage = defaultDindImageName
|
||||
}
|
||||
return dindImage
|
||||
}
|
||||
|
||||
func NewInstance(session *types.Session) (*types.Instance, error) {
|
||||
//TODO: Validate that a session can only have 10 instances
|
||||
|
||||
//TODO: Validate that a session can only have 5 instances
|
||||
//TODO: Create in redis
|
||||
|
||||
instance, err := CreateInstance(session.Id)
|
||||
log.Printf("NewInstance - using image: [%s]\n", dindImage)
|
||||
instance, err := CreateInstance(session.Id, dindImage)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Loading…
x
Reference in New Issue
Block a user