Docker打包Java8,Python37环境共存镜像

思路
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
相关推荐
容器魔方6 小时前
华为云亮相 KubeCon China 2025,开源生态引领 AI 时代技术跃迁
云原生·容器·云计算
老兵发新帖10 小时前
Kubernetes架构解析
容器·架构·kubernetes
容器魔方1 天前
Volcano v1.12 正式发布!驱动云原生AI与批量计算向智能高效新阶段演进
云原生·容器·云计算
Johny_Zhao1 天前
CentOS Stream 8 高可用 Kuboard 部署方案
linux·网络·python·网络安全·docker·信息安全·kubernetes·云计算·shell·yum源·系统运维·kuboard
爱瑞瑞1 天前
云原生学习笔记(八) Docker 实战:宿主机与容器的信息交互与共享策略
docker·容器
程序员老乔1 天前
【Dify系列】【一】【安装与部署】【ubuntu22.04安装docker部署dify1.4.2】
运维·docker·容器
sealaugh321 天前
docker(学习笔记第一课) 使用nginx +https + wordpress
笔记·学习·docker
爱瑞瑞1 天前
云原生学习笔记(七) Docker 实战:使用 Docker 快速构建 Oracle 12c 容器
docker·oracle
exe4521 天前
使用docker中的ollama
运维·docker·容器
IT成长日记2 天前
【Docker基础】Docker核心概念:命名空间(Namespace)之NET详解
运维·docker·容器·namespace·net