一、实验背景
为了缩减镜像体积,我们一般基于Alpine或者Ubuntu打镜像,但有时CentOS也不失为一个选择。
下面我们演示一下怎么基于CentOS7.x官方镜像,编写Dockerfile打一个jre镜像。
二、实验环境
操作系统:CentOS7.5 Minimal
IP: 192.168.1.107
三、 安装docker,拉取基础镜像
关闭selinux
# setenforce 0
# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
安装docker
# yum -y install yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum list docker-ce --showduplicates | sort -r
# yum -y install docker-ce-18.06.0.ce
# systemctl start docker
# systemctl status docker
# systemctl enable docker
# docker version
设置镜像加速
# curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
# systemctl restart docker
拉取CentOS7.x基础镜像
# docker pull centos:centos7
# docker images
# docker run -it --rm centos:centos7 cat /etc/redhat-release
下载 Java SE Runtime Environment 8u212
https://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
四、编写Dockerfile
# mkdir /root/jreDockerfile
# cp jre-8u212-linux-x64.tar.gz /root/jreDockerfile
# cp libstdc++.so.6.0.21 /root/jreDockerfile
# chmod 755 /root/jreDockerfile/libstdc++.so.6.0.21
# cd /root/jreDockerfile
# vim Dockerfile
########################################################
FROM centos:centos7
ENV JRE_VERSION="8u212"
ADD jre-${JRE_VERSION}-linux-x64.tar.gz /usr/local
COPY libstdc++.so.6.0.21 /usr/lib64
RUN rm -f /usr/lib64/libstdc++.so.6 \
&& chmod 755 /usr/lib64/libstdc++.so.6.0.21 \
&& ln -s /usr/lib64/libstdc++.so.6.0.21 /usr/lib64/libstdc++.so.6
ENV JAVA_HOME="/usr/local/jre1.8.0_212"
ENV PATH=${JAVA_HOME}/bin:$PATH
##########################################################
五、根据dockerfile打镜像
# docker build -f Dockerfile -t centos:jre8u212 .
六、参考
Dockerfile reference
https://docs.docker.com/v17.09/engine/reference/builder
Best practices for writing Dockerfiles
https://docs.docker.com/develop/develop-images/dockerfile_best-practices
Linux上编译安装gcc5.3.0
https://www.cnblogs.com/damonxu/p/6434265.html
编高gcc解决libstdc++的版本问题
https://blog.csdn.net/na_beginning/article/details/53413997
网友评论