欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

docker镜像制作方法

程序员文章站 2022-07-14 11:27:21
...

docker commit方式

1.1 load原来的镜像

docker load < ubuntu.tar

$ docker images |grep ubuntu

ubuntu	latest	4df32b58d0a5	3 months ago	411.3 MB

1.2 docker run

docker run --name test1 -idt ubuntu:latest bash

1.3 进容器,修改后commit

docker commit container_id ubuntu:0122

$ docker images |grep ubuntu

ubuntu	latest	4df32b58d0a5	3 months ago	411.3 MB
ubuntu	0122	57aff222e9c5	11 seconds ago	500.8 MB

1.4 docker save

docker save ubuntu:0122 > test.tar


docker export方式

2.1 load原来的镜像

docker load < ubuntu.tar

$ docker images |grep ubuntu

ubuntu	latest	4df32b58d0a5	3 months ago	411.3 MB

2.2 docker run

docker run --name test2 -idt ubuntu:latest bash

2.3 进容器,修改后export

docker export -o ubuntu_docker.tar container_id

2.4 docker import

docker import ubuntu_docker.tar ubuntu:build

$ docker images |grep ubuntu

ubuntu	latest	4df32b58d0a5	3 months ago	411.3 MB
ubuntu	build	5c12f1652881	9 seconds ago	411.3 MB

2.5 新建Dockerfile,docker build

Dockerfile:

# File Author / Maintainer
FROM ubuntu:build
Maintainer "Marvin"
$ ls -l

total 880820
-rw-r--r-- 1 root   root         408 Jan  23 14:19 Dockerfile
-rw------- 1 root   root   450969600 Jan  23 13:21 ubuntu_docker.tar

docker build -t ubuntu:0123 .

$ docker images |grep ubuntu

ubuntu	latest	4df32b58d0a5	3 months ago	411.3 MB
ubuntu	build	5c12f1652881	2 minutes ago	411.3 MB
ubuntu	0123	75d08b42fcbc	21 seconds ago	439.3 MB

2.6 docker save

docker save ubuntu:0123 > test.tar

相关标签: 常用