Docker容器遷移


1.將容器保存為鏡像(先把容器停止運行不然會有問題)

docker commit 容器名稱 保存的新鏡像名稱

操作:
[root@VM_0_7_centos nexus]# docker commit nexus nexus-z
sha256:511575baf7897e13c17da89e470b92a522785e2a9e61f32759eb49cc61a4140e
[root@VM_0_7_centos nexus]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nexus-z             latest              511575baf789        11 seconds ago      599MB

2.將鏡像打為壓縮包

docker save -o 打包后的文件名稱 鏡像名稱

操作:
[root@VM_0_7_centos nexus]# docker save nexus-z -o ./nexus-z.tar
[root@VM_0_7_centos nexus]# ll
total 596132
-rw-------  1 root root 610430976 Dec 31 16:33 nexus-z.tar

3.將打包后的鏡像壓縮包和掛載的文件夾遷移(Mac可以使用Transmit工具)

4.鏡像恢復

docker load -i 鏡像保存的tar包

操作:

[root@localhost nexus]# docker load -i ./nexus-z.tar

5.修改docker-compose.yml文件

version: '3.7'
services:
  nexus:
    restart: always
    image: nexus-z #修改這里依賴的鏡像
    container_name: nexus
    ports:
      - 8081:8081
    volumes:
      - /usr/local/docker/nexus/data:/nexus-data

6.根據docker-compose生成容器

[root@localhost nexus]# docker-compose up -d
Creating network "nexus_default" with the default driver
Creating nexus ... done
通過查看日志發現沒有讀寫文件權限(Permission denied):
[root@localhost nexus]# docker logs 57ee
Warning:  Cannot open log file: ../sonatype-work/nexus3/log/jvm.log
Warning:  Forcing option -XX:LogFile=/tmp/jvm.log
OpenJDK 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to Permission denied
java.io.FileNotFoundException: ../sonatype-work/nexus3/tmp/i4j_ZTDnGON8hezynsMX2ZCYAVDtQog=.lock (Permission denied)
修改文件夾操作權限
[root@localhost nexus]# chmod -R 777 data
[root@localhost nexus]# ll
total 596132
drwxrwxrwx. 16  777 root      4096 Dec 31 16:55 data


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM