默认情况下Docker的存放位置为:/var/lib/docker
可以通过下面命令查看具体位置:
sudo docker info | grep "Docker Root Dir"
指定镜像和容器存放路径的参数是–graph=/var/lib/docker,我们只需要修改配置文件指定启动参数即可。
Docker 的配置文件可以设置大部分的后台进程参数,在各个操作系统中的存放位置不一致,在 Ubuntu 中的位置是:/etc/default/docker,在 CentOS 中的位置是:/etc/sysconfig/docker。
如果是 CentOS 则添加下面这行:
OPTIONS=--graph="/mnt/docker" --selinux-enabled -H fd://
cat /etc/sysconfig/docker
# /etc/sysconfig/docker # Modify these options if you want to change the way the docker daemon runs
OPTIONS='--graph=/mnt/docker --selinux-enabled --log-driver=journald --signature-verification=false'
if [ -z "${DOCKER_CERT_PATH}" ]; then
DOCKER_CERT_PATH=/etc/docker
fi
# Do not add registries in this file anymore. Use /etc/containers/registries.conf
# from the atomic-registries package.
#
载入配置重启服务 systemctl daemon-reload
service docker restart 查看配置是否生效
sudo docker info | grep "Docker Root Dir" Docker Root Dir: /mnt/docker
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
cargo.caicloudprivatetest.com/data-infra_pro/data-infra pic_do_co_1.0.7 fbf6e24f9a94 About an hour ago 1.45 GB
cargo.caicloudprivatetest.com/data-infra_pro/data-infra ins-sync-df_1.0.2 c3ebeb3cfde5 days ago 1.45 GB
cargo.caicloudprivatetest.com/data-infra_pro/data-infra ins-sync-df_1.0.1 d23dbfa92c47 days ago 1.45 GB
cargo.caicloudprivatetest.com/data-infra_pro/data-infra market-sync-df_1.0.1 d23dbfa92c47 days ago