Docker 增加可用磁盘空间

Docker 增加可用磁盘空间

我试图了解如何增加 docker 为容器提供的可用空间。

TL;DR - 如何将更多硬盘空间分配给 docker 容器?

我的核心系统:

docker info
Containers: 15
 Running: 12
 Paused: 0
 Stopped: 3
Images: 19
Server Version: 17.06.2-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 6e23458c129b551d5c9871e5174f6b1b7f6d1170
runc version: 810190ceaa507aa2727d7ae6f4790c76ec150bd2
init version: 949e6fa
Security Options:
 seccomp
  Profile: default
Kernel Version: 4.9.58-xxxx-std-ipv6-64
Operating System: Debian GNU/Linux 9 (stretch)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 7.625GiB
Name: ns3306175
ID: 6YS2:EC6G:OSLT:4NB4:HMAQ:UQON:P6VO:WZJQ:ZCYO:BW3K:VZG5:AGW3
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

WARNING: No cpu cfs quota support
WARNING: No cpu cfs period support

运行 df -h

/dev/root        20G  5.9G   13G  33% /
devtmpfs        3.9G     0  3.9G   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           3.9G  404M  3.5G  11% /run
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda2       487M   24M  435M   6% /boot
/dev/sda4       1.8T   68M  1.7T   1% /home
overlay          20G  5.9G   13G  33% /var/lib/docker/overlay2/af4736dc572f48a34fd13bfd9c139358fefbbd79c8bd26716b26ba9dd2fe894d/merged
shm              64M     0   64M   0% /var/lib/docker/containers/c5b5bd3ebcf6a45558aa995711f4e2678582cbf7b21a11c087965de2a5a1c34/shm .. and more

我现在的想法 - 我希望在我的容器中拥有可用的 sda4 空间。如果我生成一个容器和 df -h 我只能访问:

overlay          20G  5.9G   13G  33% /
tmpfs           3.9G     0  3.9G   0% /dev
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/root        20G  5.9G   13G  33% /etc/hosts
shm              64M     0   64M   0% /dev/shm
tmpfs           3.9G     0  3.9G   0% /sys/firmware

答案1

您可以将 docker 目录移动到下面的某个位置/home,并创建一个/var/lib/docker指向新位置的符号链接。例如:

### shut down docker first
systemctl stop docker

mv /var/lib/docker /home/
ln -s /home/docker/ /var/lib/

### restart docker now
systemctl start docker

/home/docker如果已存在,请使用另一个目录。

除了 / 的符号链接之外var/lib/docker -> /home/docker,您还可以重新配置 docker,以便它期望在 /home 而不是 /var/lib 下找到其目录。

相关内容