首页 > 代码库 > 如何创建基于Alpine Linux的JRE环境

如何创建基于Alpine Linux的JRE环境

  • Alpine的更新源配置文件repositories内容,如果自建源,可以替换成本地的源,国外源实在太慢


  • Alpine的更新源配置文件repositories内容,如果自建源,可以替换成本地的源,国外源实在太慢

  1. [root@localhost jre8]#  cat repositories

  2. http://nl.alpinelinux.org/alpine/v3.5/main

  3. http://nl.alpinelinux.org/alpine/v3.5/community


  • Dockerfile 内容如下

  1. FROM alpine:3.5

  2. MAINTAINER jre8.111

  3. ENV JAVA_HOME=/usr/lib/jvm/default-jvm/jre

  4. add repositories /etc/apk/repositories

  5. RUN apk upgrade --update-cache; \

  6.    apk add openjdk8-jre; \

  7.    rm -rf /tmp/* /var/cache/apk/*

  8. CMD ["java", "-version"]


  • 执行命令创建docker镜像

  1. [root@localhost jre8]#  docker build -t 192.168.138.123/docker-jre:8u111_14r1 .


  • 确认是否执行成功

  1. [root@localhost jre8]# docker images

  2. REPOSITORY                  TAG                 IMAGE ID            CREATED             SIZE

  3. 192.168.138.123/docker-jre   8u111_14r1          abd8e22c1bb1        14 seconds ago      76.8 MB

  4. docker.io/alpine            3.5                 88e169ea8f46        3 weeks ago         3.98 MB

  5. docker.io/alpine            latest              88e169ea8f46        3 weeks ago         3.98 MB


  • 运行容器看看内容是否正常

  1. [root@localhost jre8]# docker run --name test -tid   abd8e22c1bb1  sh

  2. [root@localhost jre8]# docker-enter   test

  3. 3d876724639b:~# java -version

  4. openjdk version "1.8.0_111"

  5. OpenJDK Runtime Environment (IcedTea 3.2.0) (Alpine 8.111.14-r1)

  6. OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)

  • docker-enter是什么,把下面的脚本保存,放置到/bin/下面 

  1. [root@10 ~]# vim /bin/docker-enter

  2. #!/bin/sh

  3. if [ -e $(dirname "$0")/nsenter ]; then

  4.        # with boot2docker, nsenter is not in the PATH but it is in the same folder

  5.        NSENTER=$(dirname "$0")/nsenter

  6. else

  7.        NSENTER=nsenter

  8. fi

  9. if [ -z "$1" ]; then

  10.        echo "Usage: `basename "$0"` CONTAINER [COMMAND [ARG]...]"

  11.        echo ""

  12.        echo "Enters the Docker CONTAINER and executes the specified COMMAND."

  13.        echo "If COMMAND is not specified, runs an interactive shell in CONTAINER."

  14. else

  15.        PID=$(docker inspect --format "{{.State.Pid}}" "$1")

  16.        if [ -z "$PID" ]; then

  17.          exit 1

  18.        fi

  19.        shift

  20.        OPTS="--target $PID --mount --uts --ipc --net --pid --"

  21.        if [ -z "$1" ]; then

  22.          "$NSENTER" $OPTS su - root

  23.        else

  24.          "$NSENTER" $OPTS env --ignore-environment -- "$@"

  25.        fi

  26. fi

  27. [root@10 ~]# chmod +x /bin/docker-enter

























本文出自 “纳米龙” 博客,请务必保留此出处http://arlen.blog.51cto.com/7175583/1893405

如何创建基于Alpine Linux的JRE环境