首页 > 代码库 > 如何创建基于Alpine Linux的JRE环境
如何创建基于Alpine Linux的JRE环境
Alpine的更新源配置文件repositories内容,如果自建源,可以替换成本地的源,国外源实在太慢
Alpine的更新源配置文件repositories内容,如果自建源,可以替换成本地的源,国外源实在太慢
[root@localhost jre8]# cat
repositorieshttp://nl.alpinelinux.org/alpine/v3.5/main
http://nl.alpinelinux.org/alpine/v3.5/community
Dockerfile 内容如下
FROM alpine:3.5
MAINTAINER jre8.111
ENV JAVA_HOME=/usr/lib/jvm/default-jvm/jre
add repositories /etc/apk/repositories
RUN apk upgrade --update-cache; \
apk add openjdk8-jre; \
rm -rf /tmp/* /var/cache/apk/*
CMD ["java", "-version"]
执行命令创建docker镜像
[root@localhost jre8]# docker build -t
192
.168.138.123
/docker-jre:8u111_14r1 .
确认是否执行成功
[root@localhost jre8]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192
.168.138.123
/docker-jre 8u111_14r1 abd8e22c1bb1 14 seconds ago 76.8 MBdocker.io/alpine 3.5 88e169ea8f46 3 weeks ago 3.98 MB
docker.io/alpine latest 88e169ea8f46 3 weeks ago 3.98 MB
运行容器看看内容是否正常
[root@localhost jre8]# docker run --name test -tid abd8e22c1bb1 sh
[root@localhost jre8]# docker-enter test
3d876724639b:~# java -version
openjdk version "1.8.0_111"
OpenJDK Runtime Environment (IcedTea 3.2.0) (Alpine 8.111.14-r1)
OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)
docker-enter是什么,把下面的脚本保存,放置到/bin/下面
[root@10 ~]# vim /bin/docker-enter
#!/bin/sh
if [ -e $(dirname "$0")/nsenter ]; then
# with boot2docker, nsenter is not in the PATH but it is in the same folder
NSENTER=$(dirname "$0")/nsenter
else
NSENTER=nsenter
fi
if [ -z "$1" ]; then
echo "Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]"
echo ""
echo "Enters the Docker CONTAINER and executes the specified COMMAND."
echo "If COMMAND is not specified, runs an interactive shell in CONTAINER."
else
PID=$(docker inspect --format "{{.State.Pid}}" "$1")
if [ -z "$PID" ]; then
exit 1
fi
shift
OPTS="--target $PID --mount --uts --ipc --net --pid --"
if [ -z "$1" ]; then
"$NSENTER" $OPTS su - root
else
"$NSENTER" $OPTS env --ignore-environment -- "$@"
fi
fi
[root@10 ~]# chmod +x /bin/docker-enter
本文出自 “纳米龙” 博客,请务必保留此出处http://arlen.blog.51cto.com/7175583/1893405
如何创建基于Alpine Linux的JRE环境