diff --git a/config/default.go b/config/default.go index 27bd9872..baa463c4 100644 --- a/config/default.go +++ b/config/default.go @@ -203,6 +203,22 @@ func NewConfig() *Config { }, LogDriver: "json-file", }, + "preload-system-images": { + Image: "preload", + Privileged: true, + Labels: project.NewSliceorMap(map[string]string{ + DETACH: "false", + SCOPE: SYSTEM, + }), + VolumesFrom: []string{ + "command-volumes", + "system-volumes", + }, + Volumes: []string{ + "/var/run/system-docker.sock:/var/run/docker.sock", + "/var/lib/system-docker/preload:/mnt/preload", + }, + }, "cloud-init-pre": { Image: "cloudinit", Privileged: true, @@ -215,6 +231,9 @@ func NewConfig() *Config { Environment: project.NewMaporslice([]string{ "CLOUD_INIT_NETWORK=false", }), + Links: []string{ + "preload-system-images", + }, VolumesFrom: []string{ "command-volumes", "system-volumes", @@ -246,6 +265,7 @@ func NewConfig() *Config { }), Net: "host", Links: []string{ + "preload-user-images", "cloud-init-pre", "network", }, @@ -311,6 +331,25 @@ func NewConfig() *Config { "all-volumes", }, }, + "preload-user-images": { + Image: "preload", + Privileged: true, + Labels: project.NewSliceorMap(map[string]string{ + DETACH: "false", + SCOPE: SYSTEM, + }), + Links: []string{ + "dockerwait", + }, + VolumesFrom: []string{ + "command-volumes", + "system-volumes", + }, + Volumes: []string{ + "/var/run/docker.sock:/var/run/docker.sock", + "/var/lib/docker/preload:/mnt/preload", + }, + }, "console": { Image: "console", Privileged: true, diff --git a/docker/container.go b/docker/container.go index 1813b3fd..8d95de7a 100644 --- a/docker/container.go +++ b/docker/container.go @@ -242,12 +242,6 @@ func (c *Container) requiresUserDocker() bool { return true } - for _, v := range c.ContainerCfg.Service.Volumes { - if strings.Index(v, "/var/run/docker.sock") != -1 { - return true - } - } - return false } @@ -267,10 +261,12 @@ func (c *Container) addLink(link string) { func (c *Container) parseService() { if c.requiresSyslog() { c.addLink("syslog") + log.Infof("[%v]: Implicitly linked to 'syslog'", c.Name) } if c.requiresUserDocker() { c.addLink("dockerwait") + log.Infof("[%v]: Implicitly linked to 'dockerwait'", c.Name) } else if c.ContainerCfg.Service.Image != "" { client, err := NewClient(c.dockerHost) if err != nil { @@ -281,6 +277,7 @@ func (c *Container) parseService() { i, _ := client.InspectImage(c.ContainerCfg.Service.Image) if i == nil { c.addLink("network") + log.Infof("[%v]: Implicitly linked to 'network'", c.Name) } } diff --git a/scripts/dockerimages/13-preload b/scripts/dockerimages/13-preload new file mode 100644 index 00000000..660f1d92 --- /dev/null +++ b/scripts/dockerimages/13-preload @@ -0,0 +1,3 @@ +FROM base +COPY scripts/dockerimages/scripts/preload.sh / +CMD ["/preload.sh"] diff --git a/scripts/dockerimages/scripts/preload.sh b/scripts/dockerimages/scripts/preload.sh new file mode 100755 index 00000000..d8b67fce --- /dev/null +++ b/scripts/dockerimages/scripts/preload.sh @@ -0,0 +1,40 @@ +#!/bin/bash +set -e + +BASE=${1:-${PRELOAD_DIR}} +BASE=${BASE:-/mnt/preload} + +should_load() { + file=${1} + if [[ ${file} =~ \.done$ ]]; then echo false + elif [ -f ${file} ]; then + if [ ! -e ${file}.done ]; then echo true + elif [[ $(stat -c %Y ${file}) > $(stat -c %Y ${file}.done) ]]; then echo true + else echo false + fi + else echo false + fi +} + +if [ -d ${BASE} ]; then + echo Preloading docker images from ${BASE}... + + for file in $(ls ${BASE}); do + path=${BASE}/${file} + loading=$(should_load ${path}) + if [ ${loading} == "true" ]; then + CAT="cat ${path}" + if [[ ${file} =~ \.t?gz$ ]]; then CAT="${CAT} | gunzip"; fi + if [[ ${file} =~ \.t?xz$ ]]; then CAT="${CAT} | unxz"; fi + CAT="${CAT} | docker load" + echo loading from ${path} + eval ${CAT} || : + touch ${path}.done || : + fi + done + + echo Done. +else + echo Can not preload images from ${BASE}: not a dir or does not exist. +fi +