0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Docker イメージのエクスポートと別マシンでの利用手順

0
Posted at

忘れるのでメモしておくシリーズ

移行フロー

基本は以下の流れ:

docker save
   ↓
ファイルコピー
   ↓
docker load
   ↓
docker run

方法①:docker image をファイルとして保存 → 別マシンで読み込み(推奨)

■ 元マシン(イメージを持っている側)

① 対象イメージを確認

docker images

例:

REPOSITORY      TAG       IMAGE ID
myapp           latest    a1b2c3d4e5f6

② イメージを tar ファイルとして保存

docker save -o myapp.tar myapp:latest

複数イメージもまとめて保存可能:

docker save -o bundle.tar image1:tag image2:tag

③ tar ファイルを別マシンへコピー

scp myapp.tar user@other-machine:/tmp/

USBや共有フォルダでも可能。


■ 別マシン側

④ イメージを読み込み

docker load -i myapp.tar

⑤ イメージ確認

docker images

⑥ コンテナ作成・起動

docker run -d --name myapp_container myapp:latest

ポートやボリューム指定例:

docker run -d \
  -p 8080:8080 \
  -v /data:/data \
  --name myapp_container \
  myapp:latest

方法②:コンテナ状態を丸ごと保存する場合

■ 元マシン

① コンテナをイメージ化

docker commit container_name myapp_snapshot

② 保存

docker save -o myapp_snapshot.tar myapp_snapshot

■ 別マシン

docker load -i myapp_snapshot.tar
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?