Linux
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
您可以將 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 下找到其目錄。