Ubuntuでdocker-ceがapt upgrade後に起動しなくなる問題

## 環境
- os: Ubuntu 16.04.5 LTS
- Docker: ```Docker version 18.09.0, build 4d60db4```
    - [公式ドキュメント](https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce-1)を参考にインストールを実施
- 何が起きても復旧できる方のみ試して下さい。

## 事象
- ```apt upgrade```でDockerイメージを更新したところ、起動出来なくなっていた。

```shell-session:~/
# apt upgrade docker-ce
--------
省略
--------
Setting up docker-ce (5:18.09.0~3-0~ubuntu-xenial) ...
update-alternatives: using /usr/bin/dockerd-ce to provide /usr/bin/dockerd (dockerd) in auto mode
Failed to start docker.service: Unit docker.socket not found.
docker.service couldn't start.
```

- どうやらdocker.socket周りで起動に失敗している模様。

```shell-session:~/
root@dubuntu ~ # service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: enabled
   Active: inactive (dead)
     Docs: https://docs.docker.com

Dec 08 20:01:26 dhcpd1 dockerd[7611]: time="2018-12-08T20:01:26.296706247Z" level=info
Dec 08 20:01:26 dhcpd1 dockerd[7611]: time="2018-12-08T20:01:26.297263853Z" level=info
Dec 08 20:01:26 dhcpd1 dockerd[7611]: time="2018-12-08T20:01:26.305617356Z" level=info
Dec 08 20:01:26 dhcpd1 systemd[1]: Started Docker Application Container Engine.
Dec 08 20:32:06 dhcpd1 systemd[1]: Stopping Docker Application Container Engine...
Dec 08 20:32:06 dhcpd1 dockerd[7611]: time="2018-12-08T20:32:06.911024416Z" level=info
Dec 08 20:32:06 dhcpd1 dockerd[7611]: time="2018-12-08T20:32:06.913177285Z" level=info
Dec 08 20:32:06 dhcpd1 dockerd[7611]: time="2018-12-08T20:32:06.913197690Z" level=info
Dec 08 20:32:06 dhcpd1 dockerd[7611]: time="2018-12-08T20:32:06.913363042Z" level=info
Dec 08 20:32:07 dhcpd1 systemd[1]: Stopped Docker Application Container Engine.
```

- どうやらsystemd unitファイルに誤った内容が記載されてしまいっているということらしい。
[参考](https://stackoverflow.com/questions/42217526/cannot-start-docker-daemon-in-centos7)



- たまたま同じバージョンのDockerが正しく動作しているサーバーがあったのでunitファイルを確認したところ、違う場所を参照していた。
  - 動いているホストのunitファイル：```/lib/systemd/system/docker.service```
  - 駄目なホストのunitファイル：```/etc/systemd/system/docker.service```

```shell-session:動いているホスト
root@ubuntu # service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e
   Active: active (running) since Fri 2018-12-07 17:27:18 JST; 1 day 12h ago
```

```shell-session:駄目なホスト
root@ubuntu # service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/etc/systemd/system/docker.service; enabled; vendor preset: enabled
   Active: inactive (dead)
```

## 解決策

- **```/etc/systemd/system/docker.service```を吹き飛ばした。**

```shell-session:~/
# rm /etc/systemd/system/docker.service
```

- Docker 再起動

```shell-session:~/
# service docker start
```

- **治った**
    - unitファイルの参照先が/lib/systemd/以下に変わった。

```shell-session:~/
# service docker status
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled
   Active: active (running) since Sat 2018-12-08 20:50:48 UTC; 5s ago
```


## 原因
- apt upgrade時に走るアップグレードスクリプトのバグ？

## おまけ
- 正常動作するunitファイルの内容


```config:/lib/systemd/system/docker.service
 
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service
Wants=network-online.target

[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H unix://
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always

# Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229.
# Both the old, and new location are accepted by systemd 229 and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst=3

# Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230.
# Both the old, and new name are accepted by systemd 230 and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s

# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity

# Comment TasksMax if your systemd version does not supports it.
# Only systemd 226 and above support this option.
TasksMax=infinity

# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

# kill only the docker process, not all processes in the cgroup
KillMode=process

[Install]
WantedBy=multi-user.target

```