我用Docker for AWS创建了一个Docker swarm集群。在这个集群的每个节点中,我发现Docker root dir是/var/lib/docker
,但是,我在文件系统中找不到这个目录。
docker info
显示:
~ $ docker info
Containers: 7
Running: 7
Paused: 0
Stopped: 0
Images: 9
Server Version: 17.06.0-ce
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: awslogs
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: active
NodeID: k8nw4j8bt0mhip541vurvd785
Is Manager: false
Node Address: 10.x.y.z
Manager Addresses:
10.x.y.z:2377
10.x.y.z:2377
10.x.y.z:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: cfb82a876ecc11b5ca0977d1733adbe58599088a
runc version: 2d41c047c83e09a6d61d464906feb2a2f3c52aa4
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.36-moby
Operating System: Alpine Linux v3.5
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 7.293GiB
Name: ip-10-x-y-z.us-west-2.compute.internal
ID: 4YZB:UYHX:REW2:ENBZ:AAEW:BS6T:HB5B:OQCE:FRBU:DPXX:SJWV:GRGL
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: 163
Goroutines: 233
System Time: 2018-06-13T07:04:01.824290758Z
EventsListeners: 5
Registry: https://index.docker.io/v1/
Labels:
os=linux
region=us-west-2
availability_zone=us-west-2a
instance_type=m3.large
node_type=worker
Experimental: true
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
它清楚地显示Docker Root Dir
是/var/lib/docker
,但是,当我使用ls
时,它说无法找到目录:
~ $ sudo ls /var/lib/docker
ls: /var/lib/docker: No such file or directory
~ $ sudo ls -al /var/lib/
total 20
drwxr-xr-x 5 root root 4096 Jun 25 2017 .
drwxr-xr-x 1 root root 4096 Jun 27 2017 ..
drwxr-xr-x 2 root root 4096 Jun 25 2017 apk
drwxr-xr-x 2 root root 4096 Jun 25 2017 misc
drwxr-xr-x 2 root root 4096 Jun 25 2017 udhcpd
关于Docker的磁盘使用情况,Docker使用了超过2.3GB的磁盘
/ $ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 9 6 2.361GB 1.702GB (72%)
Containers 7 7 665.1kB 0B (0%)
Local Volumes 6 6 19.85MB 0B (0%)
关于文件系统使用情况,df
命令显示使用2.9GB空间,这是预期的,因为仅Docker消耗超过2.3GB。
/ $ sudo df -h
Filesystem Size Used Available Use% Mounted on
overlay 19.7G 2.9G 15.8G 15% /
tmpfs 3.6G 0 3.6G 0% /dev
tmpfs 3.6G 0 3.6G 0% /sys/fs/cgroup
tmpfs 3.6G 161.2M 3.5G 4% /etc/group
tmpfs 3.6G 161.2M 3.5G 4% /etc/passwd
tmpfs 3.6G 161.2M 3.5G 4% /etc/shadow
/dev/xvdb1 19.7G 2.9G 15.8G 15% /etc/ssh
tmpfs 3.6G 161.2M 3.5G 4% /home/docker
/dev/xvdb1 19.7G 2.9G 15.8G 15% /var/log
/dev/xvdb1 19.7G 2.9G 15.8G 15% /etc/resolv.conf
/dev/xvdb1 19.7G 2.9G 15.8G 15% /etc/hostname
/dev/xvdb1 19.7G 2.9G 15.8G 15% /etc/hosts
shm 64.0M 0 64.0M 0% /dev/shm
tmpfs 746.8M 916.0K 745.9M 0% /var/run/docker.sock
tmpfs 3.6G 161.2M 3.5G 4% /usr/bin/docker
tmpfs 3.6G 0 3.6G 0% /proc/kcore
tmpfs 3.6G 0 3.6G 0% /proc/timer_list
tmpfs 3.6G 0 3.6G 0% /proc/sched_debug
tmpfs 3.6G 0 3.6G 0% /sys/firmware
同时,关于磁盘使用情况:
/ $ sudo du -h -d 1
0 ./sys
31.5M ./usr
1.8M ./etc
0 ./proc
12.0K ./home
216.0K ./sbin
4.0K ./tmp
8.0K ./run
4.0K ./root
1.4M ./bin
114.3M ./var
4.0K ./mnt
16.0K ./media
2.8M ./lib
0 ./dev
4.0K ./srv
152.2M .
du
报告只使用了152.2M磁盘,/var
文件夹只使用了114.3M,似乎du
也找不到/ var / lib / docker,而且Docker以某种方式存储其数据(2.3 + GB)du
不能找。
如果我使用docker inspect
检查此节点上的一个正在运行的容器,它会显示多个文件夹位于/var/lib/docker
下。
任何人都可以对原因有所了解吗?谢谢。
这是因为当您使用docker用户(https://docs.docker.com/docker-for-aws/faqs/#what-are-the-editions-containers-running-after-deployment)ssh时,aws的docker使用shell容器,因此您实际上无法访问根目录所在的主机。
您可以通过特权容器访问主机,首先使用docker用户进行sshing,然后运行如下命令:docker run --rm -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh