思路
shell
构建CentOS7容器
并在该容器中配置相关 Java8,Python37 环境
将该配置好环境容器打包成最终镜像
构建 CentOS7 容器
shell
mkdir -p /usr/local/src/centos7_with_jdk8_python37
cd /usr/local/src/centos7_with_jdk8_python37
vim Dockerfile
dockerfile
FROM centos:7
MAINTAINER "ai_service"
shell
# 打包CentOS7镜像
docker build -t centos7_with_jdk8_python37:1.0.0 .
# 启动容器
docker run -id \
--net=host \
--name=centos7_with_jdk8_python37_1.0.0 \
centos7_with_jdk8_python37:1.0.0
容器内配置Java8环境
shell
docker exec -it centos7_with_jdk8_python37_1.0.0 /bin/bash
shell
# 配置JDK8环境
yum -y install java-1.8.0-openjdk.x86_64 && \
sed -i '$a\JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk.x86_64' /etc/profile && \
sed -i '$a\PATH=$PATH:$JAVA_HOME/bin' /etc/profile && \
sed -i '$a\CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar' /etc/profile && \
sed -i '$a\export JAVA_HOME CLASSPATH PATH' /etc/profile && \
source /etc/profile && \
java -version
容器内配置Pyhton37环境
shell
docker exec -it centos7_with_jdk8_python37_1.0.0 /bin/bash
shell
# 配置Python3环境
yum -y install numactl vim libffi libffi-devel openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc automake autoconf libtool make wget && \
cd /usr/local/src/ && \
wget https://mirrors.huaweicloud.com/python/3.7.0/Python-3.7.0.tar.xz && \
tar xvf Python-3.7.0.tar.xz && \
mv Python-3.7.0 /usr/local/python-3.7 && \
cd /usr/local/python-3.7/ && \
./configure --prefix=/usr/local/sbin/python-3.7 && \
make && make install && \
rm -rf /usr/bin/python && \
ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python && \
ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python3 && \
ln -sv /usr/local/sbin/python-3.7/bin/python3 /usr/bin/python37 && \
sed -i 1s/python/python2.7/ /usr/bin/yum && \
sed -i 1s/python/python2.7/ /usr/libexec/urlgrabber-ext-down && \
sed -i 1s/python/python2.7/ /usr/bin/yum-config-manager
提交容器成镜像
shell
# 提交容器成镜像
docker commit -m="has update" -a=" ai_service" centos7_with_jdk8_python37_1.0.0 centos7_with_jdk8_python37:2.0.0
# 保存镜像到本地后清除 centos7_with_jdk8_python37_1.0.0,2.0.0 容器及镜像
docker save -o ./centos7_with_jdk8_python37:2.0.0.tar centos7_with_jdk8_python37:2.0.0
docker load -i ./centos7_with_jdk8_python37:2.0.0.tar