我有一个已安装到AWS ECS集群实例的EBS卷。此EBS卷安装在/data下:

$ cat /etc/fstab
...
UUID=xxx /data   ext4    defaults,nofail        0       2
$ ls -la /data
total 28
drwxr-xr-x  4 1000 1000  4096 May 14 06:11 .
dr-xr-xr-x 26 root root  4096 May 15 21:18 ..
drwxr-xr-x  4 root root  4096 May 14 06:11 .ethereum
drwx------  2 1000 1000 16384 May 14 05:29 lost+found

编辑:/ proc / mounts 的输出
[ec2-user@xxx ~]$ cat /proc/mounts
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
/dev/xvda1 / ext4 rw,noatime,data=ordered 0 0
devtmpfs /dev devtmpfs rw,relatime,size=4078988k,nr_inodes=1019747,mode=755 0 0
devpts /dev/pts devpts rw,relatime,gid=5,mode=620,ptmxmode=000 0 0
tmpfs /dev/shm tmpfs rw,relatime 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw,relatime 0 0
cgroup /cgroup/blkio cgroup rw,relatime,blkio 0 0
cgroup /cgroup/cpu cgroup rw,relatime,cpu 0 0
cgroup /cgroup/cpuacct cgroup rw,relatime,cpuacct 0 0
cgroup /cgroup/cpuset cgroup rw,relatime,cpuset 0 0
cgroup /cgroup/devices cgroup rw,relatime,devices 0 0
cgroup /cgroup/freezer cgroup rw,relatime,freezer 0 0
cgroup /cgroup/hugetlb cgroup rw,relatime,hugetlb 0 0
cgroup /cgroup/memory cgroup rw,relatime,memory 0 0
cgroup /cgroup/perf_event cgroup rw,relatime,perf_event 0 0
/dev/xvdf /data ext4 rw,relatime,data=ordered 0 0

现在,我想在我的ECS任务定义中将/data/.ethereum作为Docker卷挂载到/geth/.ethereum:
{
  ...
  "containerDefinitions": [
    {
      ...
      "volumesFrom": [],
      "mountPoints": [
        {
          "containerPath": "/geth/.ethereum",
          "sourceVolume": "ethereum_datadir",
          "readOnly": null
        }
      ],
      ...
    }
  ],
  ...
  "volumes": [
    {
      "host": {
        "sourcePath": "/data/.ethereum"
      },
      "name": "ethereum_datadir"
    }
  ],
  ...
}

运行该任务后,似乎已正确装入该卷:
$  docker inspect -f '{{ json .Mounts }}' f5c36d9ea0d6 | python -m json.tool
[
    {
        "Destination": "/geth/.ethereum",
        "Mode": "",
        "Propagation": "rprivate",
        "RW": true,
        "Source": "/data/.ethereum"
    }
]

但是,如果我在安装点内的容器内创建文件,则该文件将不在主机上。
[ec2-user@xxx .ethereum]$ docker exec -it f5c36d9ea0d6 bash
root@f5c36d9ea0d6:/geth# cat "Hello World!" > /geth/.ethereum/hello_world.txt
cat: Hello World!: No such file or directory
root@f5c36d9ea0d6:/geth# echo "Hello World!" > /geth/.ethereum/hello_world.txt
root@f5c36d9ea0d6:/geth# cat /geth/.ethereum/hello_world.txt
Hello World!
root@f5c36d9ea0d6:/geth# exit
exit
[ec2-user@xxx ~]$ cat /data/.ethereum/hello_world.txt
cat: /data/.ethereum/hello_world.txt: No such file or directory

不知何故文件系统没有被共享。有任何想法吗?

最佳答案

找到了问题。
似乎对于Docker而言,必须在启动Docker守护程序之前在主机实例上创建任何挂载点(例如,用于EBS卷),否则Docker会在您不注意的情况下将文件写入实例的根文件系统中。

我停止了Docker,卸载了EBS卷,清理了所有内容,再次安装了EBS卷,然后启动了Docker。现在,Docker似乎可以识别挂载点,并按需将所有内容写入我的EBS卷中。

09-25 20:56