怎样制作docker基础镜像

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)