Skip to content
An`s Weblog
Go back

Saving and Loading Images

→ Xuất và Nhập Docker Image bằng file TAR

Mục tiêu bài học:

Xuất Image sang file .tar

1. Tạo thư mục chứa file TAR

mkdir output
cd output

2. Câu lệnh export image

docker image save --output weather-app-latest.tar <dockerhub-username>/weather-app:latest
Thành phầnÝ nghĩa
docker image saveLệnh để xuất (save) một Docker Image thành file .tar
--output weather-app-latest.tarChỉ định tên file xuất ra: file nén tar sẽ có tên là weather-app-latest.tar
<dockerhub-username>/weather-app:latestĐây là tên đầy đủ của Docker Image muốn lưu, bao gồm:
-<dockerhub-username>: Tên tài khoản DockerHub
-weather-app: Tên image
-latest: Thẻ tag của image (phiên bản mới nhất)

Hoặc:

docker image save <image-name> > weather-app-latest.tar

3. Kiểm tra file TAR

tar tvf weather-app-latest.tar

Kết quả:

4. Nén file TAR

gzip weather-app-latest.tar

Xóa image trên local

docker image rm <dockerhub-username>/weather-app:latest

Tải lại image từ file TAR

1. Load lại image

docker image load --input weather-app-latest.tar

Hoặc:

docker image load -i weather-app-latest.tar

2. Kiểm tra image

docker image ls | grep weather-app

Kết quả:

Tổng kết lệnh

LệnhChức năng
docker image saveExport image thành file TAR
docker image loadNhập lại image từ file TAR
tar tvfKiểm tra cấu trúc file TAR
gzipNén file TAR
docker image rmXóa image

Ứng dụng thực tế


Share this post:

Previous Post
Using the Volume Instruction
Next Post
Image History