Docker容器存放目录磁盘空间问题
安装系统时分区/var
目录是存放日志的,一般不会给很大的空间。docker
默认数据存放目录是/var
目录,很容易就被直接打爆
实验平台:CentOS 7.4
Docker版本:17.05.0-ce
操作步骤:
一、查看docker使用空间
1.查看服务器磁盘空间
$ df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 1.8T 31G 1.8T 2% /
devtmpfs 31G 0 31G 0% /dev
tmpfs 31G 0 31G 0% /dev/shm
tmpfs 31G 650M 31G 3% /run
tmpfs 31G 0 31G 0% /sys/fs/cgroup
/dev/sdb3 497M 128M 369M 26% /boot
/dev/sdb2 500M 9.8M 490M 2% /boot/efi
/dev/mapper/centos-home 10G 9.0G 1.1G 90% /home
/dev/mapper/centos-var 15G 15G 20K 100% /var
tmpfs 6.2G 0 6.2G 0% /run/user/0
overlay 15G 15G 20K 100% /var/lib/docker/overlay/741009b2c5b45d571640630a81ddf42395ff6b1d62b0bf9b0955a9071579c622/merged
overlay 15G 15G 20K 100% /var/lib/docker/overlay/711da16ae2c6d82beb554d7175abfd9b4710efba59d5c8513d3d1b15c5c7025b/merged
shm 64M 0 64M 0% /var/lib/docker/containers/8a5c2f129d1ee716d6134dbda82b0241077c15637f3bc563c0a2eda01e63261f/shm
shm 64M 0 64M 0% /var/lib/docker/containers/fdf48d4fd1d216644a67b1d39fcc4e2b8cae94fdd6c344472740c2dd58a4ca50/shm
#发现docker默认存储路径/var已经爆了
2.查看Docker磁盘情况
$ docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 9 9 4.378GB 223.7MB (5%)
Containers 10 10 7.08GB 0B (0%)
Local Volumes 56 6 2.224GB 307.7MB (13%)
二、清理docker磁盘
1.docker
自带清理命令
$ docker system prune
WARNING! This will remove:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all build cache
Are you sure you want to continue? [y/N] y
Deleted Containers:
2f7c62d4dc6be9576429826eff202365bb536ee0b509dd644ef6d035c7c1ea1d
Deleted Images:
untagged: registry.cn-hangzhou.*****.com/jarbo/tomcat:9.0.8-jre8-slim
untagged: registry.cn-hangzhou.*****.com/jarbo/tomcat@sha256:4a2f7d516b3877fa5aa8dc462bf00641d664a4de28d2e0eb1ec5c619cf54de0b
untagged: registry.cn-hangzhou.*****.com/jarbo/tomcat-service:18.12.10
deleted: sha256:f3c2e02b9ba7c21b5128146c8af558175896c359ce7da87729f7c8d3fb15c3f1
deleted: sha256:ed1d86d921f9b2e7a593e6c6f60f9b8f5838758ea22a5e4b1ab5296543a554ea
deleted: sha256:36422c92fd09fccbd3ee534e41b8e4ede1fe52b00ce5d936d5157bf74322d679
deleted: sha256:090105bdc844a2dda7e6f36d375706dddf99328dc21739cd608afa4d5c39b75c
deleted: sha256:da44825225568d966606f6ae10724677f365a382788e5881ade9bc562f22cdce
Total reclaimed space: 109.8MB
#可以清理磁盘,删除关闭的容器、无用的数据卷和网络,以及dangling镜像(即无tag的镜像)
#清理了109.8MB的空间
$ docker system prune -a
#清理得更加彻底,可以将没有容器使用Docker镜像都删掉。注意,这两个命令会把你暂时关闭的容器,以及暂时没有用到的Docker镜像都删掉了
2.手动清理Docker``镜像
/容器
/数据卷
对于旧版的Docker(版本1.13之前),是没有docker >system命令的,因此需要进行手动清理。这里给出几个常用的命
$ docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm
#删除所有关闭的容器
$ docker rmi $(docker images | grep "^<none>" | awk "{print $3}")
#删除所有dangling镜像(即无tag的镜像)
$docker volume rm $(docker volume ls -qf dangling=true)
#删除所有dangling数据卷(即无用的volume)
三、更换docker存储路径
清理不掉的还是占用过大只能迁移数据了;最好是在docker安装完后,第一时间修改docker默认存储位置为其他大目录或者磁盘中。避免迁移数据过程中造成的风险。
1.查看默认路径
$ docker info
docker info
Containers: 10
Running: 10
Paused: 0
Stopped: 0
Images: 9
Server Version: 17.06.2-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: 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: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 48
Total Memory: 61.95GiB
Name: localhost.localdomain
ID: IAVH:UXNN:6OUH:NADL:BO62:7O62:6MBM:677Y:6OKN:XVZH:4DRF:JSKH
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
#可以发现默认路径为/var ;-> Docker Root Dir: /var/lib/docker
2.停止服务,不能再写入数据
$ systemctl stop docker
3.使用rsync
迁移Docker
数据;数据路多的话会比较慢
$ rsync -avz /var/lib/docker/* /root/dockerdir/lib/docker/
4.创建配置文件
$ mkdir -p /etc/systemd/system/docker.service.d/
$ vim /etc/systemd/system/docker.service.d/devicemapper.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/home/docker/lib/docker
5.重启服务
$ systemctl daemon-reload
$ systemctl restart docker
6.查看路径
$ docker info
docker info
Containers: 10
Running: 10
Paused: 0
Stopped: 0
Images: 9
Server Version: 17.06.2-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: 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: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 48
Total Memory: 61.95GiB
Name: localhost.localdomain
ID: IAVH:UXNN:6OUH:NADL:BO62:7O62:6MBM:677Y:6OKN:XVZH:4DRF:JSKH
Docker Root Dir: /home/docker/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
#可以发现默认路径为/home ;-> Docker Root Dir: /home/docker/lib/docker
7.查看镜像
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.********/mis/misrobot-bigdata 1.0 c5b186e47de6 7 days ago 128MB
registry.********/mis/misrobot-web-node 18.12.03 eff897b71d2d 7 days ago 2.76GB
registry.********/mis/misrobot-service 18.12.03 0993ddf543b4 7 days ago 333MB
registry.********/mis/platform 18.12.03 8146495ec9fd 7 days ago 368MB
registry.********/mis/misrobot-service 18.11.16 9a80bcbba7c0 3 weeks ago 333MB
registry.********/mis/misrobot-edms 18.11.16 3f2930ab8a9d 3 weeks ago 265MB
registry.********/mis/misrobot-edms 18.12.03 3f2930ab8a9d 3 weeks ago 265MB
registry.********/mis/platform 18.11.16 fcbbfa56235c 3 weeks ago 365MB
registry.********/mis/resource-server 1.0 2210919dafb2 3 weeks ago 2.22GB
registry.********/mis/misrobot-web-node 18.11.16 978e9084d09d 3 weeks ago 2.69GB
registry.********/library/mysql-backup 1.0 a28f88d4c85d 6 weeks ago 42.9MB
registry.********/mis/********-web-node 2.8.1 b0ad86bb5bfb 7 weeks ago 2.42GB
registry.********/mis/platform 2.8.1 0809e8d3c7c1 7 weeks ago 364MB
registry.********/mis/misrobot-service 2.8.1 2eb42758836d 7 weeks ago 333MB
registry.********/mis/misrobot-edms 2.8.1 597cf2738d4b 7 weeks ago 265MB
registry.********/mis/onlyoffice-documentserver 5.2.2.2 a983f4ec853d 2 months ago 1.74GB
registry.********/mis/doorservice 2.7.2 5cc58079e09f 3 months ago 133MB
registry.********/library/nginx fdfs 42e82383d0c1 6 months ago 443MB
registry.********/library/rabbitmq 3.7.5-management-alpine 0688d022cb86 7 months ago 83MB
registry.********/library/mysql 5.7 0d16d0a97dd1 7 months ago 372MB
registry.********/library/fastdfs 5.11 e41af134c20d 13 months ago 378MB
#服务都没有问题后可以清理磁盘了
Over~
版权协议须知!
本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
1313 0 2018-12-10
博主卡片
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。
现在时间 2024-12-28
今日天气
站点统计
- 文章总数:241篇
- 分类总数:29个
- 评论总数:12条
- 本站总访问量 353812 次
@xiaozi 最后的分享的镜像下载地址打不开 服务器没有开机吗?
@yuanyuan 为什么我的4b安装centos7.9 插上tf卡 显示不兼...
@Wong arrhenius 牛比
@MakerFace 厉害了!
@TongSir 老哥 更新下我的友链链接 https://blog.ton...