Linux

docker 이미지 생성 및 저장

ravon 2024. 8. 8. 09:41

 

- 생성.

docker commit {container_name} {image_name}

docker commit db_master test123

 

- dockerfile  이미지 생성

docker build ${option} ${dockerfile directory}

 

root@Ubuntu-Docker:~# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED              SIZE
test123      latest    c63d18cb5ec7   About a minute ago   396MB
index        1.1       919dab24b11b   13 days ago          148MB

 

- docker 이미지 파일로 저장.

save

-도커 이미지를 rar 파일로 추출

- docker save -o test123.tra test123:latest

 

load

-추출된 tar 파일을 이미지로 불러옴

-docker load -i test123.tar

 

#################################################################


root@Ubuntu-Docker:~# docker save --help

Usage:  docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Aliases:
  docker image save, docker save

Options:
  -o, --output string   Write to a file, instead of STDOUT
root@Ubuntu-Docker:~# docker save test123.tar test123
cowardly refusing to save to a terminal. Use the -o flag or redirect
root@Ubuntu-Docker:~# docker save -o test123.tar test123
root@Ubuntu-Docker:~# ls -al
total 393268
drwx------  5 root root      4096 Aug  8 00:34 .
drwxr-xr-x 22 root root      4096 Aug  8 00:13 ..
-rw-------  1 root root      4519 Aug  2 08:29 .bash_history
-rw-r--r--  1 root root      3106 Apr 22 13:04 .bashrc
drwx------  3 root root      4096 Aug  2 02:06 .docker
-rw-------  1 root root        20 Aug  2 01:13 .lesshst
-rw-r--r--  1 root root       161 Apr 22 13:04 .profile
drwx------  2 root root      4096 Jul 25 00:45 .ssh
-rw-------  1 root root     13611 Aug  2 02:13 .viminfo
drwxr-xr-x  3 root root      4096 Aug  2 02:13 first_docker
-rw-------  1 root root 402647552 Aug  8 00:34 test123.tar

 

 

root@Ubuntu-Docker:~# docker load -i test123.tar
Loaded image: test123:latest
root@Ubuntu-Docker:~# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
test123      latest    c63d18cb5ec7   10 minutes ago   396MB
index        1.1       919dab24b11b   13 days ago      148MB
mariadb      10.6      4cb983cc407c   8 weeks ago      396MB
redis        7.0.0     53aa81e8adfa   2 years ago      117MB
root@Ubuntu-Docker:~#

############################################################################