Docker部署以及更改数据目录

1.centos7下安装 docker

安装必要服务

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

#更新yum源 && 安装docker

sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum -y install docker-ce

设置开机启动以及启动服务

systemctl enable docker && systemctl start docker

2.ubuntu18.04下安装 docker

sudo apt-get remove docker docker-engine docker-ce docker.iosudo apt-get updatesudo apt-get install     ca-certificates     curl     gnupg     lsb-releasecurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpgecho   "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/nullsudo apt-get updatesudo apt-get install docker-ce docker-ce-cli containerd.io

3.优化镜像使用阿里云镜像(适用所有环境)

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://tnnxu6o2.mirror.aliyuncs.com"]
}
设置开机启动以及启动服务systemctl enable docker && systemctl restart docker

场景:docker默认数据目录/var/lib/docker由于根目录大小不足,需要迁移到home目录/home/docker/data/

1.创建新目录,停止docker

可以尽量删除本机上的容器镜像,只保留基础镜像

mkdir -p /home/docker/data/
systemctl stop docker

2. 同步数据

rsync -r -avz /var/lib/docker/ /home/docker/data/

3.修改开机启动项,在ExecStart 后指定目录

cat /usr/lib/systemd/system/docker.service  |grep ExecStart
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph=/home/docker/data/
systemctl daemon-reload && systemctl start docker
systemctl status docker
docker info
docker images -a
发表评论

相关文章