如何创建基于Alpine Linux的JRE环境
Alpine的更新源配置文件repositories内容,如果自建源,可以替换成本地的源,国外源实在太慢
Alpine的更新源配置文件repositories内容,如果自建源,可以替换成本地的源,国外源实在太慢
[root@localhost jre8]# catrepositorieshttp://nl.alpinelinux.org/alpine/v3.5/mainhttp://nl.alpinelinux.org/alpine/v3.5/community
Dockerfile 内容如下
FROM alpine:3.5MAINTAINER jre8.111ENV JAVA_HOME=/usr/lib/jvm/default-jvm/jreadd repositories /etc/apk/repositoriesRUN apk upgrade --update-cache; \apk add openjdk8-jre; \rm -rf /tmp/* /var/cache/apk/*CMD ["java", "-version"]
执行命令创建docker镜像
[root@localhost jre8]# docker build -t192.168.138.123/docker-jre:8u111_14r1 .
确认是否执行成功
[root@localhost jre8]# docker imagesREPOSITORY TAG IMAGE ID CREATED SIZE192.168.138.123/docker-jre 8u111_14r1 abd8e22c1bb1 14 seconds ago 76.8 MBdocker.io/alpine 3.5 88e169ea8f46 3 weeks ago 3.98 MBdocker.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 test3d876724639b:~# java -versionopenjdk 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/shif [ -e $(dirname "$0")/nsenter ]; then# with boot2docker, nsenter is not in the PATH but it is in the same folderNSENTER=$(dirname "$0")/nsenterelseNSENTER=nsenterfiif [ -z "$1" ]; thenecho "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."elsePID=$(docker inspect --format "{{.State.Pid}}" "$1")if [ -z "$PID" ]; thenexit 1fishiftOPTS="--target $PID --mount --uts --ipc --net --pid --"if [ -z "$1" ]; then"$NSENTER" $OPTS su - rootelse"$NSENTER" $OPTS env --ignore-environment -- "$@"fifi[root@10 ~]# chmod +x /bin/docker-enter
本文出自 “纳米龙” 博客,请务必保留此出处http://arlen.blog.51cto.com/7175583/1893405