赞
踩
本文主要介绍镜像制作,以及周边比如镜像支持中文等问题
将本机系统里主要文件打成tar 包,然后编写dockerfile.txt 文件,最后docker build,以下以centos 7.9 为例
mkdir /docker
tar -cvpf /docker/systemcentos79.tar --directory=/ --exclude=docker --exclude=proc --exclude=run --exclude=sys .
可以借鉴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"]
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
[root@localhost tmp]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centosbyxxxx cento7.9.2009.xxxx 69f6af05b9f0 34 seconds ago 1.38GB
官网下载的镜像默认不支持中文,比如gitlab-runner 镜像,是以debian 系统制作的默认也不支持中文,如果代码里有中文名称的文件,打包就会报错。
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
FROM gitlab/gitlab-runner:v14.10.1
MAINTAINER tobias
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
dpkg-reconfigure --frontend=noninteractive locales && \
update-locale LANG=en_US.UTF-8
ENV LANG en_US.UTF-8
VOLUME ["/etc/gitlab-runner", "/home/gitlab-runner"]
ENTRYPOINT ["/usr/bin/dumb-init", "/entrypoint"]
CMD ["run", "--user=gitlab-runner", "--working-directory=/home/gitlab-runner"]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。