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
相关推荐
闲云自留地21 小时前
K8s 的记忆大脑!ETCD 集群部署、etcdctl 命令与备份恢复全通关
容器·kubernetes·etcd
孙克旭_1 天前
k8s基础组件与创建资源
运维·docker·容器·kubernetes
java_logo2 天前
Docker 部署 EmulatorJS:轻松搭建浏览器复古游戏平台
游戏·docker·容器·复古游戏·轩辕镜像·emulatorjs·红白机
吴声子夜歌2 天前
Kubernetes权威指南——网络原理(一)
网络·容器·kubernetes
方便面不加香菜2 天前
Docker Container --容器及容器的操作案例详解
运维·docker·容器
无人生还别怕2 天前
如何搭建docker仓库(轻量级)registry
linux·运维·docker·云原生·容器·registry·openanolisos
YYYing.3 天前
【K8s系列 (一) 】Docker与容器(上篇)
docker·云原生·容器·kubernetes
csdn_aspnet3 天前
使用 Docker 和 RedisInsight 设置 Redis 以进行本地开发
redis·docker·容器·redisinsight
余槐i3 天前
MySQL 8.0 联合索引走错:为什么加了索引查询反而从 200ms 变成 8s
java·spring boot·mysql·docker·性能优化
csdn_aspnet3 天前
如何在本地 Docker 容器中运行 Redis,并使用 Redis Insight 和 Redis CLI 进行管理
redis·docker·容器