修改docker数据存储路径
docker
的默认的数据存储路径为/var/lib/docker/
,如果其所在磁盘空间较小,容易出现磁盘空间不足的问题,这是就需要修改docker
的数据存储路径,并迁移数据
docker
的数据存储路径可通过docker info
命令查看
[root]# docker info
...
Docker Root Dir: /var/lib/docker/
Debug Mode: false
Registry: https://index.docker.io/v1/
...
1.执行命令df -h
,找一个大的磁盘, 然后创建新的数据目录
df -h
mkdir -p /data/docker/lib
2.停止docker
服务
systemctl stop docker
3.迁移/var/lib/docker
目录下的数据到新创建的目录/data/docker/lib
rsync -avz /var/lib/docker /data/docker/lib/
4.修改docker
配置文件/etc/docker/daemon.json
,默认没有,需要自己创建
{
"data-root": "/data/docker/lib/docker"
}
5.然后重启docker
服务就ok了
systemctl daemon-reload
systemctl restart docker
6.执行docker info
确认一下Docker Root Dir
修改是否已经生效
[root]# docker info
...
Docker Root Dir: /a8root/data/docker/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
...
7.执行docker images
和docker ps -a
确认一下之前的镜像和容器是否正常
[root@tx3-suggest-dev08 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7 6c20ffa54f86 7 days ago 448MB
redis latest fad0ee7e917a 2 months ago 105MB
tensorflow/serving 2.3.0 e0fe79fbb64f 12 months ago 286MB
elasticsearch 7.2.0 0efa6a3de177 2 years ago 861MB
elasticsearch 5.6.3 7e555e9f4ab4 3 years ago 581MB
[root@tx3-suggest-dev08 docker]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a8ad4663a11b mysql:5.7 "docker-entrypoint.s…" 5 days ago Exited (0) About an hour ago mysql
2ca8588f37a5 elasticsearch:5.6.3 "/docker-entrypoint.…" 2 months ago Exited (143) 2 hours ago es
c9645fe96ce8 elasticsearch:7.2.0 "/usr/local/bin/dock…" 2 months ago Exited (143) 2 months ago elasticsearch
9ddbadad9900 redis "docker-entrypoint.s…" 2 months ago Exited (0) 2 hours ago redis-test
8.确定没问题后就可以删除/var/lib/docker/
目录中的文件来释放磁盘空间了
rm -rf /var/lib/docker