From: 011netservice@gmail.com Date: 2025-06-23 Subject: ExportImport-Ubuntu https://svc.011.idv.tw/CodeHelper/Docker/ExportImport-Ubuntu.txt 歡迎來信交流, 訂購軟體需求. #### Ubuntu 22.04 上 匯出 docker repository 為 gitlab/gitlab-ce 到另一台 ubuntu 在來源主機上匯出 Docker 映像檔 1. 確認映像存在: sudo docker images 2. 匯出映像為 tar 檔案: sudo docker save -o gitlab-ce.tar gitlab/gitlab-ce docker save 是用來匯出 映像(image),而不是容器(container) 如果是要備份容器的 資料(例如 GitLab 的設定、資料庫、使用者檔案等),那就需要: 停止容器(避免資料寫入中) 備份 volume 掛載的資料夾,例如 /srv/gitlab/config、/srv/gitlab/data 等, 如下: docker stop gitlab tar -czvf gitlab-volumes-backup.tar.gz /srv/gitlab/ 將映像檔傳送到目標主機 可使用 scp 或其他檔案傳輸工具: scp gitlab-ce.tar YourUserName@target-host:/path/to/destination 替換 YourUserName 和 target-host 為目標主機的使用者名稱與 IP 或主機名稱。 在目標主機上載入映像檔 1. 登入目標主機: ssh user@target-host 2. 載入映像: docker load -i /path/to/destination/gitlab-ce.tar 3. 確認映像已載入: docker images 啟動 GitLab 容器 (選用) 如果你想直接啟動 GitLab CE 容器,可以使用以下指令(請根據需求調整): docker run --detach \ --hostname gitlab.example.com \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab \ --restart always \ --volume /srv/gitlab/config:/etc/gitlab \ --volume /srv/gitlab/logs:/var/log/gitlab \ --volume/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce --- export_and_transfer_gitlab.sh #!/bin/bash # Step 1: Export Docker image on source host echo "Exporting Docker image 'gitlab/gitlab-ce' to gitlab-ce.tar..." docker save -o gitlab-ce.tar gitlab/gitlab-ce # Step 2: Transfer the image to the target host echo "Transferring gitlab-ce.tar to target host..." scp gitlab-ce.tar user@target-host:/path/to/destination # Step 3: Load the image on the target host echo "Loading Docker image on target host..." ssh user@target-host 'docker load -i /path/to/destination/gitlab-ce.tar' # Step 4 (Optional): Run GitLab container on the target host echo "Running GitLab container on target host..." ssh user@target-host 'docker run --detach \ --hostname gitlab.example.com \ --publish 443:443 --publish 80:80 --publish 22:22 \ --name gitlab \ --restart always \ --volume /srv/gitlab/config:/etc/gitlab \ --volume /srv/gitlab/logs:/var/log/gitlab \ --volume /srv/gitlab/data:/var/opt/gitlab \ gitlab/gitlab-ce' echo "Script execution completed."