(Docker notes): Build your own centos mirror

The official centos7 dockerfile

FROM scratch
ADD centos-7-x86_64-docker.tar.xz /

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="20200809" \
    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-08-09 00:00:00+01:00"

CMD ["/bin/bash"]
  • Most of the images in DockerHub are FROM scratch from this basic image , and then configure the required software and configuration to build
  • Then we are based on the official image, plus some environment we need

Build your own centos mirror case

  • Step ①: Create a dockerfile directory to store some files
cd /home
mkdir dockerfile

 

  • Step ②: Create a dockerfile file, name it whatever you want, here is named mydockerfile
vim mydockerfile
  • Step ③: Write dockerfile script instructions
FROM centos      # 基础镜像
MAINTAINER Aut<[email protected]>    # 作者信息

ENV MYPATH /usr/local    # 创建一个变量 存放一个值
WORKDIR $MYPATH    # 启动后的工作目录,就是进入容器后的默认目录

RUN yum -y install vim    # 执行指令安装 vim
RUN yum -y install net-tools    # 执行指令安装 net-tools

EXPOSE 80    # 暴露端口

CMD echo $MYPATH    # 输出 MYPATH 变量
CMD echo "----end----"    # 输出信息
CMD /bin/bash    # 启动后用bash命令行
  • Step ④: Build the image
 docker build -f dockerfile文件路径 -t 镜像名:[tag] .

  • Step ⑤: Prompt for successful construction
Successfully built f5932e99cf90
Successfully tagged mycentos:0.6

  • Step ⑥: Test run
docker run -it mycentos:0.6

  • Step ⑦: View the history through the history command, you can see how the mirror is made step by step
docker history 镜像ID

Guess you like

Origin blog.csdn.net/baidu_41388533/article/details/108564097