Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #111 from ibuildthecloud/non-standard-root
Browse files Browse the repository at this point in the history
Support non-/var/lib/docker root
  • Loading branch information
ibuildthecloud authored Dec 14, 2016
2 parents 1a98185 + 2aa1be9 commit 0ae92dc
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions core/compute/compute_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strconv"
"strings"
"sync"
"time"

"github.com/Sirupsen/logrus"
Expand All @@ -25,6 +26,11 @@ import (
"golang.org/x/net/context"
)

var (
dockerRootOnce = sync.Once{}
dockerRoot = ""
)

func createContainer(dockerClient *client.Client, config *container.Config, hostConfig *container.HostConfig, networkConfig *network.NetworkingConfig,
imageTag string, instance model.Instance, name string, progress *progress.Progress) (string, error) {
labels := config.Labels
Expand Down Expand Up @@ -117,6 +123,17 @@ func setupPorts(config *container.Config, instance model.Instance, hostConfig *c
}
}

func getDockerRoot(client *client.Client) string {
dockerRootOnce.Do(func() {
info, err := client.Info(context.Background())
if err != nil {
panic(err.Error())
}
dockerRoot = info.DockerRootDir
})
return dockerRoot
}

func setupVolumes(config *container.Config, instance model.Instance, hostConfig *container.HostConfig, client *client.Client, progress *progress.Progress) error {

volumes := instance.Data.Fields.DataVolumes
Expand All @@ -135,6 +152,18 @@ func setupVolumes(config *container.Config, instance model.Instance, hostConfig
} else {
mode = "rw"
}

// Redirect /var/lib/docker:/var/lib/docker to where Docker root really is
if parts[0] == "/var/lib/docker" && parts[1] == "/var/lib/docker" {
root := getDockerRoot(client)
if root != "/var/lib/docker" {
volumesMap[root] = struct{}{}
binds = append(binds, fmt.Sprintf("%s:%s:%s", root, parts[1], mode))
binds = append(binds, fmt.Sprintf("%s:%s:%s", root, root, mode))
continue
}
}

bind := fmt.Sprintf("%s:%s:%s", parts[0], parts[1], mode)
binds = append(binds, bind)
}
Expand Down

0 comments on commit 0ae92dc

Please sign in to comment.