Don't use separate bind mount for container

Since we're not not mounting anything but the base filesystem outside
the container we no longer need the separate bind mount at
/var/lib/docker/container/$id/root in order to see the base filesystem
without extra mounts. So, we drop this and mount (again) the container
root directly at the real basefs mountpoint.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
This commit is contained in:
Alexander Larsson 2014-03-04 10:16:09 +01:00
parent 6c266c4b42
commit bf1b27dfcc
5 changed files with 5 additions and 43 deletions

View file

@ -374,7 +374,7 @@ func (b *buildFile) checkPathForAddition(orig string) error {
func (b *buildFile) addContext(container *runtime.Container, orig, dest string, remote bool) error {
var (
origPath = path.Join(b.contextPath, orig)
destPath = path.Join(container.BasefsPath(), dest)
destPath = path.Join(container.RootfsPath(), dest)
)
// Preserve the trailing '/'
if strings.HasSuffix(dest, "/") {

View file

@ -71,7 +71,7 @@ func containerFileExists(eng *engine.Engine, id, dir string, t utils.Fataler) bo
t.Fatal(err)
}
defer c.Unmount()
if _, err := os.Stat(path.Join(c.BasefsPath(), dir)); err != nil {
if _, err := os.Stat(path.Join(c.RootfsPath(), dir)); err != nil {
if os.IsNotExist(err) {
return false
}

View file

@ -532,7 +532,7 @@ func (container *Container) Start() (err error) {
populateCommand(container)
container.command.Env = env
if err := mountVolumesForContainer(container, envPath); err != nil {
if err := setupMountsForContainer(container, envPath); err != nil {
return err
}
@ -843,8 +843,6 @@ func (container *Container) cleanup() {
}
}
unmountVolumesForContainer(container)
if err := container.Unmount(); err != nil {
log.Printf("%v: Failed to umount filesystem: %v", container.ID, err)
}
@ -1039,12 +1037,6 @@ func (container *Container) EnvConfigPath() (string, error) {
// This method must be exported to be used from the lxc template
// This directory is only usable when the container is running
func (container *Container) RootfsPath() string {
return path.Join(container.root, "root")
}
// This is the stand-alone version of the root fs, without any additional mounts.
// This directory is usable whenever the container is mounted (and not unmounted)
func (container *Container) BasefsPath() string {
return container.basefs
}

View file

@ -174,7 +174,6 @@ func (runtime *Runtime) Register(container *Container) error {
runtime.execDriver.Kill(command, 9)
}
// ensure that the filesystem is also unmounted
unmountVolumesForContainer(container)
if err := container.Unmount(); err != nil {
utils.Debugf("ghost unmount error %s", err)
}
@ -185,7 +184,6 @@ func (runtime *Runtime) Register(container *Container) error {
utils.Debugf("Container %s was supposed to be running but is not.", container.ID)
if runtime.config.AutoRestart {
utils.Debugf("Restarting")
unmountVolumesForContainer(container)
if err := container.Unmount(); err != nil {
utils.Debugf("restart unmount error %s", err)
}

View file

@ -4,10 +4,8 @@ import (
"fmt"
"github.com/dotcloud/docker/archive"
"github.com/dotcloud/docker/execdriver"
"github.com/dotcloud/docker/pkg/mount"
"github.com/dotcloud/docker/utils"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
@ -35,29 +33,9 @@ func prepareVolumesForContainer(container *Container) error {
return nil
}
func mountVolumesForContainer(container *Container, envPath string) error {
// Setup the root fs as a bind mount of the base fs
var (
root = container.RootfsPath()
runtime = container.runtime
)
if err := os.MkdirAll(root, 0755); err != nil && !os.IsExist(err) {
return nil
}
// Create a bind mount of the base fs as a place where we can add mounts
// without affecting the ability to access the base fs
if err := mount.Mount(container.basefs, root, "none", "bind,rw"); err != nil {
return err
}
// Make sure the root fs is private so the mounts here don't propagate to basefs
if err := mount.ForceMount(root, root, "none", "private"); err != nil {
return err
}
func setupMountsForContainer(container *Container, envPath string) error {
mounts := []execdriver.Mount{
{runtime.sysInitPath, "/.dockerinit", false, true},
{container.runtime.sysInitPath, "/.dockerinit", false, true},
{envPath, "/.dockerenv", false, true},
{container.ResolvConfPath, "/etc/resolv.conf", false, true},
}
@ -80,12 +58,6 @@ func mountVolumesForContainer(container *Container, envPath string) error {
return nil
}
func unmountVolumesForContainer(container *Container) {
if err := mount.Unmount(container.RootfsPath()); err != nil {
log.Printf("Failed to umount container: %v", err)
}
}
func applyVolumesFrom(container *Container) error {
if container.Config.VolumesFrom != "" {
for _, containerSpec := range strings.Split(container.Config.VolumesFrom, ",") {