零 摘要
本文主要介绍镜像制作,以及周边比如镜像支持中文等问题
一 环境信息
二 镜像制作
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 .
示例文章来源:https://www.uudwc.com/A/EvrdB/
[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
2.2 docker 容器支持中文 以debian 系列为例
官网下载的镜像默认不支持中文,比如gitlab-runner 镜像,是以debian 系统制作的默认也不支持中文,如果代码里有中文名称的文件,打包就会报错。文章来源地址https://www.uudwc.com/A/EvrdB/
2.2.1 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
2.2.2 gitlabrunner 为例
FROM gitlab/gitlab-runner:v14.10.1
MAINTAINER weibi2
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"]