We discussed this at the docker plumbers meetup and for tools and
working on the system for things like boot2docker and coreos this is
needed. You can already bypass this check so we felt it is ok to start
allowing this feature.
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@docker.com> (github: crosbymichael)
| ... | ... |
@@ -960,3 +960,14 @@ func TestRootWorkdir(t *testing.T) {
|
| 960 | 960 |
|
| 961 | 961 |
logDone("run - workdir /")
|
| 962 | 962 |
} |
| 963 |
+ |
|
| 964 |
+func TestAllowBindMountingRoot(t *testing.T) {
|
|
| 965 |
+ s, _, err := cmd(t, "run", "-v", "/:/host", "busybox", "ls", "/host") |
|
| 966 |
+ if err != nil {
|
|
| 967 |
+ t.Fatal(s, err) |
|
| 968 |
+ } |
|
| 969 |
+ |
|
| 970 |
+ deleteAllContainers() |
|
| 971 |
+ |
|
| 972 |
+ logDone("run - bind mount / as volume")
|
|
| 973 |
+} |
| ... | ... |
@@ -132,8 +132,8 @@ func parseRun(cmd *flag.FlagSet, args []string, sysInfo *sysinfo.SysInfo) (*Conf |
| 132 | 132 |
// add any bind targets to the list of container volumes |
| 133 | 133 |
for bind := range flVolumes.GetMap() {
|
| 134 | 134 |
if arr := strings.Split(bind, ":"); len(arr) > 1 {
|
| 135 |
- if arr[0] == "/" {
|
|
| 136 |
- return nil, nil, cmd, fmt.Errorf("Invalid bind mount: source can't be '/'")
|
|
| 135 |
+ if arr[1] == "/" {
|
|
| 136 |
+ return nil, nil, cmd, fmt.Errorf("Invalid bind mount: desination can't be '/'")
|
|
| 137 | 137 |
} |
| 138 | 138 |
// after creating the bind mount we want to delete it from the flVolumes values because |
| 139 | 139 |
// we do not want bind mounts being committed to image configs |
| ... | ... |
@@ -2055,19 +2055,11 @@ func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
|
| 2055 | 2055 |
if len(job.Environ()) > 0 {
|
| 2056 | 2056 |
hostConfig := runconfig.ContainerHostConfigFromJob(job) |
| 2057 | 2057 |
// Validate the HostConfig binds. Make sure that: |
| 2058 |
- // 1) the source of a bind mount isn't / |
|
| 2059 |
- // The bind mount "/:/foo" isn't allowed. |
|
| 2060 |
- // 2) Check that the source exists |
|
| 2061 |
- // The source to be bind mounted must exist. |
|
| 2058 |
+ // the source exists |
|
| 2062 | 2059 |
for _, bind := range hostConfig.Binds {
|
| 2063 | 2060 |
splitBind := strings.Split(bind, ":") |
| 2064 | 2061 |
source := splitBind[0] |
| 2065 | 2062 |
|
| 2066 |
- // refuse to bind mount "/" to the container |
|
| 2067 |
- if source == "/" {
|
|
| 2068 |
- return job.Errorf("Invalid bind mount '%s' : source can't be '/'", bind)
|
|
| 2069 |
- } |
|
| 2070 |
- |
|
| 2071 | 2063 |
// ensure the source exists on the host |
| 2072 | 2064 |
_, err := os.Stat(source) |
| 2073 | 2065 |
if err != nil && os.IsNotExist(err) {
|