一眼姐、實(shí)驗(yàn)背景
為了縮減鏡像體積辜王,我們一般基于Alpine或者Ubuntu打鏡像呻惕,但有時CentOS也不失為一個選擇。
下面我們演示一下怎么基于CentOS7.x官方鏡像,編寫Dockerfile打一個jre鏡像浅侨。
二、實(shí)驗(yàn)環(huán)境
操作系統(tǒng):CentOS7.5 Minimal
IP: 192.168.1.107
三证膨、 安裝docker如输,拉取基礎(chǔ)鏡像
關(guān)閉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
設(shè)置鏡像加速
#? curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
# systemctl restart docker?
拉取CentOS7.x基礎(chǔ)鏡像
# 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
##########################################################
五央勒、根據(jù)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