moby/cmd/dockerd
Lei Jitang 7318eba5b2 Don't create source directory while the daemon is being shutdown, fix #30348
If a container mount the socket the daemon is listening on into
container while the daemon is being shutdown, the socket will
not exist on the host, then daemon will assume it's a directory
and create it on the host, this will cause the daemon can't start
next time.

fix issue https://github.com/moby/moby/issues/30348

To reproduce this issue, you can add following code

```
--- a/daemon/oci_linux.go
+++ b/daemon/oci_linux.go
@@ -8,6 +8,7 @@ import (
        "sort"
        "strconv"
        "strings"
+       "time"

        "github.com/Sirupsen/logrus"
        "github.com/docker/docker/container"
@@ -666,7 +667,8 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e
        if err := daemon.setupIpcDirs(c); err != nil {
                return nil, err
        }
-
+       fmt.Printf("===please stop the daemon===\n")
+       time.Sleep(time.Second * 2)
        ms, err := daemon.setupMounts(c)
        if err != nil {
                return nil, err

```

step1 run a container which has `--restart always` and `-v /var/run/docker.sock:/sock`
```
$ docker run -ti --restart always -v /var/run/docker.sock:/sock busybox
/ #

```
step2 exit the the container
```
/ # exit
```
and kill the daemon when you see
```
===please stop the daemon===
```
in the daemon log

The daemon can't restart again and fail with `can't create unix socket /var/run/docker.sock: is a directory`.

Signed-off-by: Lei Jitang <leijitang@huawei.com>
2017-05-30 22:59:51 -04:00
..
hack review code about cmd/* and fix some easy typos :D 2017-02-10 15:52:33 +08:00
config.go Expose trust key path in config 2017-05-10 14:16:27 -07:00
config_common_unix.go Deprecate --graph flag; Replace with --data-root 2017-03-30 11:24:56 +02:00
config_experimental.go Extract daemon configuration and discovery to their own package 2017-02-08 09:53:38 +01:00
config_solaris.go Extract daemon configuration and discovery to their own package 2017-02-08 09:53:38 +01:00
config_unix.go Add no-new-privileg flag 2017-05-01 15:31:56 -04:00
config_unix_test.go Remove pkg/testutil/assert in favor of testify 2017-04-14 12:03:21 -07:00
config_windows.go Deprecate --graph flag; Replace with --data-root 2017-03-30 11:24:56 +02:00
daemon.go Don't create source directory while the daemon is being shutdown, fix #30348 2017-05-30 22:59:51 -04:00
daemon_freebsd.go Windows: Wait for OOBE to prevent crashing during host update 2017-02-15 14:01:54 -08:00
daemon_linux.go Windows: Wait for OOBE to prevent crashing during host update 2017-02-15 14:01:54 -08:00
daemon_solaris.go Windows: Wait for OOBE to prevent crashing during host update 2017-02-15 14:01:54 -08:00
daemon_test.go Add daemon option to push foreign layers 2017-05-16 14:36:36 -07:00
daemon_unix.go Expose trust key path in config 2017-05-10 14:16:27 -07:00
daemon_unix_test.go Remove pkg/testutil/assert in favor of testify 2017-04-14 12:03:21 -07:00
daemon_windows.go Windows: Wait for OOBE to prevent crashing during host update 2017-02-15 14:01:54 -08:00
docker.go Merge pull request #32244 from Microsoft/jjh/panicfix 2017-04-01 20:00:59 +02:00
docker_windows.go Windows: work around Go 1.6.2/Nano Server TP5 issue 2016-05-25 11:59:28 +02:00
metrics.go Add basic prometheus support 2016-10-27 10:34:38 -07:00
README.md Fix readme doc for dockerd 2016-09-01 14:47:51 +08:00
service_unsupported.go Windows: no pidfile when service 2017-03-08 15:18:30 -08:00
service_windows.go Windows - fix panic and stderr 2017-03-31 09:51:50 -07:00

docker.go contains Docker daemon's main function.

This file provides first line CLI argument parsing and environment variable setting.