+-
怎样制作docker基础镜像
首页 专栏 docker 文章详情
0

怎样制作docker基础镜像

高线概 发布于 2 月 24 日

I use openSUSE15.2, and Docker to do operation this article describes.
这篇文章所讲的操作在openSUSE15.2 + docker环境下执行过。
To be simple, let us try to make my own system to be a Docker image.
我们简单点,试试把我自己的系统制作成一个Docker镜像。

tar your / filesystem

Move to /, execute a 'tar' command:
进入 / 目录,执行一个tar命令:

cd /
tar --one-file-system --exclude=ABCD.tar -c -f ABCD.tar .
--one-file-system
Stay in local file system when creating archive. --exclude=ABCD.tar
exclude ABCD.tar.
不把ABCD.tar放进ABCD.tar里。

Build the Docker image

At /, write a Dockerfile:

FROM scratch
ADD ABCD.tar /
FROM scracth
build this image based on the most original image of Docker - scratch.
在Docker最原始的镜像 - scratch 上构件镜像。
'scratch' is a image with empty filesystem.
'scratch'是拥有空文件系统的镜像。 ADD ABCD.tar /
'ADD' command will extract ABCD.tar, and copy them to / path of the image.
'ADD'命令会解压ABCD.tar,把文件复制到镜像的/目录下。
Don't use CMD, because CMD will not extract ABCD.tar .
不要用CMD命令,CMD命令不会解压ABCD.tar .

then execute 'docker build':

docker build -t MyFirstImage:1 .

use 'docker images' to see whether you have get this new image:

docker images

run this new image

docker exec -it MyFirstImage:1 bash 
docker
阅读 71 更新于 2 月 24 日
收藏
分享
本作品系原创, 采用《署名-非商业性使用-禁止演绎 4.0 国际》许可协议
高线概的Linux操作笔记
高线概的Linux笔记。
关注专栏
avatar
高线概

三民主义,吾党所宗,以建民国,以进大同。

3 声望
0 粉丝
关注作者
0 条评论
得票 时间
提交评论
avatar
高线概

三民主义,吾党所宗,以建民国,以进大同。

3 声望
0 粉丝
关注作者
宣传栏
目录

I use openSUSE15.2, and Docker to do operation this article describes.
这篇文章所讲的操作在openSUSE15.2 + docker环境下执行过。
To be simple, let us try to make my own system to be a Docker image.
我们简单点,试试把我自己的系统制作成一个Docker镜像。

tar your / filesystem

Move to /, execute a 'tar' command:
进入 / 目录,执行一个tar命令:

cd /
tar --one-file-system --exclude=ABCD.tar -c -f ABCD.tar .
--one-file-system
Stay in local file system when creating archive. --exclude=ABCD.tar
exclude ABCD.tar.
不把ABCD.tar放进ABCD.tar里。

Build the Docker image

At /, write a Dockerfile:

FROM scratch
ADD ABCD.tar /
FROM scracth
build this image based on the most original image of Docker - scratch.
在Docker最原始的镜像 - scratch 上构件镜像。
'scratch' is a image with empty filesystem.
'scratch'是拥有空文件系统的镜像。 ADD ABCD.tar /
'ADD' command will extract ABCD.tar, and copy them to / path of the image.
'ADD'命令会解压ABCD.tar,把文件复制到镜像的/目录下。
Don't use CMD, because CMD will not extract ABCD.tar .
不要用CMD命令,CMD命令不会解压ABCD.tar .

then execute 'docker build':

docker build -t MyFirstImage:1 .

use 'docker images' to see whether you have get this new image:

docker images

run this new image

docker exec -it MyFirstImage:1 bash