docker 镜像的制作

零 摘要

一 环境信息

二 镜像制作

2.1 基于本机系统制作镜像

将本机系统里主要文件打成tar 包,然后编写dockerfile.txt 文件,最后docker build,以下以centos 7.9 为例

2.1.1 制作tar 包

mkdir /docker
tar -cvpf /docker/systemcentos79.tar --directory=/ --exclude=docker --exclude=proc --exclude=run --exclude=sys  .

2.1.2 编写dockerfile.txt

可以借鉴dockerhub 官网的的dockerfile

FROM scratch
ADD systemcentos79.tar /

LABEL \
    org.label-schema.schema-version="1.0" \
    org.label-schema.name="CentOS Base Image" \
    org.label-schema.vendor="CentOS" \
    org.label-schema.license="GPLv2" \
    org.label-schema.build-date="20201113" \
    org.opencontainers.image.title="CentOS Base Image" \
    org.opencontainers.image.vendor="CentOS" \
    org.opencontainers.image.licenses="GPL-2.0-only" \
    org.opencontainers.image.created="2020-11-13 00:00:00+00:00"

CMD ["/bin/bash"]

2.1.3 制作docker image

centos79dockerfile.txt 跟systemcentos79.tar 在同一级目录下
制作命令

 docker build -t centosbyxxxx:cento7.9.2009.xxxx -f centos79dockerfile.txt .

示例

[root@localhost tmp]# docker build -t centosbyxxxx :cento7.9.2009.xxxx -f centos79dockerfile.txt .
[+] Building 44.1s (5/5) FINISHED                                                                                                                                                                                                                                             
 => [internal] load .dockerignore                                                                                                                                                                                                                                        0.0s
=> => transferring context: 2B                                                                                                                                                                                                                                          0.0s
=> [internal] load build definition from centos79dockerfile.txt                                                                                                                                                                                                         0.0s
=> => transferring dockerfile: 475B                                                                                                                                                                                                                                     0.0s
=> [internal] load build context                                                                                                                                                                                                                                       17.6s
=> => transferring context: 1.41GB                                                                                                                                                                                                                                     15.7s
=> [1/1] ADD systemcentos79.tar /                                                                                                                                                                                                                                      11.1s
=> exporting to image                                                                                                                                                                                                                                                  15.4s
=> => exporting layers                                                                                                                                                                                                                                                 15.4s
=> => writing image sha256:69f6af05b9f0c4b3a0e09f8deb4e03aafb77f936d9ec899f459249c4f4517fca                                                                                                                                                                             0.0s
=> => naming to docker.io/library/centosbyxxxx :cento7.9.2009.xxxx                                                                                                                                                                                                  0.0s

2.1.4 检查

[root@localhost tmp]# docker images
REPOSITORY                        TAG                     IMAGE ID       CREATED             SIZE
centosbyxxxx                    cento7.9.2009.xxxx    69f6af05b9f0   34 seconds ago      1.38GB

你可能感兴趣的:(docker,linux,运维)