Docker迁移
一、源地址上操作
1、查看
docker ps
2、停止
docker stop 78 5e c4 1f
3、压缩数据(docker本地引用的文件夹)
说明:docker引用本地文件夹为 /software
cd /software
tar -zcvf software.zip ./
4、容器生成镜像
[root@vm172-31-0-4 software]# docker commit 78 myredis sha256:89fc607685c8cb8eb77ae8b4ff87f170f0e1eef6b7d63e2b4e77b7638511ae45 [root@vm172-31-0-4 software]# docker commit 5e mygitlab sha256:5aa365de6037f16483511f06cd95fd72305aad7181d7a9e172a717b0f5695758 [root@vm172-31-0-4 software]# docker commit c4 mymysql sha256:c5f369e98677421c7f7f53676d19527115f49a27b14547c8fe178bbeb0a9f589 [root@vm172-31-0-4 software]# docker commit 1f mynginx sha256:c60ef01fe709cef958e17e90f08f1dffe190f1325ef3464709d7324d05f7101a [root@vm172-31-0-4 software]#
docker commit 容器名称 新的镜像名称
5、镜像导出为文件
docker save -o 文件名.tar 镜像名
6、传输文件到另一台服务器
scp *.zip root@120.92.86.214:/software
scp *.tar root@120.92.86.214:/software
二、目标地址上操作
1、查看
2、解压
cd /software
tar -zxvf software.zip ./
3、恢复镜像
docker load -i image-nginx.tar
4、查看镜像
5、启动镜像
docker run -d -p 80:80 --name nginx -v /software/nginx/html:/etc/nginx/html -v /software/nginx/conf:/etc/nginx -v /software/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /software/nginx/logs:/etc/nginx/logs mynginx docker run -p 3360:3306 --name mysql \ -v /software/mysql/conf:/etc/mysql \ -v /software/mysql/logs:/var/log/mysql \ -v /software/mysql/data:/var/lib/mysql \ -v /software/mysql/mysql-files:/var/lib/mysql-files \ -e MYSQL_ROOT_PASSWORD=123456 \ -d mymysql docker run -d -p 9443:443 -p 9080:80 -p 9022:22 \ --name gitlab --restart always \ --volume /software/gitlab/config:/etc/gitlab \ --volume /software/gitlab/logs:/var/log/gitlab \ --volume /software/gitlab/data:/var/opt/gitlab \ -m 300m \ --memory-swap=400m \ mygitlab
问题
1、2台服务器均为云服务器,执行scp命令外网正常,由于文件过大,使用云内网传输报错
解决方法,删除 /root/.ssh/known_hosts 中172.31.16.71的key
删除前
删除后
2、docker权限问题
docker exec -it gitlab update-permissions
docker restart gitlab
docker部署gitlab的迁移
1、进入容器
docker exec -it 容器ID /bin/bash
2、备份
gitlab-rake gitlab:backup:create /var/opt/gitlab/backups/
3、上传到目标服务器上
scp *.tar root@120.92.86.214:/software
3,新建一个gitlab
docker run -d -p 19443:443 -p 19080:80 -p 19022:22 \ --name gitlab --restart always \ --volume /software/gitlab/config:/etc/gitlab \ --volume /software/gitlab/logs:/var/log/gitlab \ --volume /software/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce
4,进去 新容器 更改权限
复制文件到 /software/gitlab/data/backups 进入容器 docker exec -it gitlab /bin/bash 进入目录 cd /var/opt/gitlab/backups 赋权 chown git.git 1605110004_2020_11_11_13.1.1_gitlab_backup.tar
5,关闭相关服务
root@925449bfe3ee:/var/opt/gitlab# gitlab-ctl stop unicorn
ok: down: unicorn: 1s, normally up
root@925449bfe3ee:/var/opt/gitlab# gitlab-ctl stop sidekiq
ok: down: sidekiq: 1s, normally up
6 开始恢复(这里不要写全名 他会自动拼接)
gitlab-rake gitlab:backup:restore BACKUP=1553072122_2019_03_20_11.1.4
结束