如何在 docker 上将 java 安装到 ubuntu?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38495646/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How install java to ubuntu on docker?
提问by user5620472
I tried use docker. I install tool docker and run. I dovnload ubuntu image and run on docker. I make all by this link
我试过使用码头工人。我安装工具docker并运行。我 dovnload ubuntu 图像并在 docker 上运行。我通过这个链接制作所有内容
For install ubuntu I used docker run -it ubuntu bash
对于我使用的安装 ubuntu docker run -it ubuntu bash
After that I run this ubuntu docker run -i -t ubuntu:latest /bin/bash
之后我运行这个 ubuntu docker run -i -t ubuntu:latest /bin/bash
After start I placed root@9bca9a2a537d:/#
开始后我放置 root@9bca9a2a537d:/#
Now I want install java and start some app on this java.
现在我想安装 java 并在这个 java 上启动一些应用程序。
I tried install java root@cf50a6fdfc10:/# apt-get install default-jre
我试过安装java root@cf50a6fdfc10:/# apt-get install default-jre
When this installed i try run this command java -version
and I see
安装后,我尝试运行此命令,java -version
然后我看到
root@2e62f448f783:/# java -version
openjdk version "1.8.0_91"
OpenJDK Runtime Environment (build 1.8.0_91-8u91-b14-0ubuntu4~16.04.1-b14)
OpenJDK 64-Bit Server VM (build 25.91-b14, mixed mode)
after that i exit from ubuntu
之后我从 ubuntu 退出
root@2e62f448f783:/# exit
and run again. And when ubuntu started i try
并再次运行。当 ubuntu 启动时,我尝试
root@20cefe55e2eb:/# java -version
bash: java: command not found
How can I install java or start this java version?
如何安装 java 或启动此 java 版本?
回答by Gautier
As paulscott56said, you can add those lines in your Dockerfile:
正如paulscott56所说,您可以在 Dockerfile 中添加这些行:
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
apt-get -y install default-jre-headless && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
https://hub.docker.com/r/pataquets/default-jre-headless/~/dockerfile/
https://hub.docker.com/r/pataquets/default-jre-headless/~/dockerfile/
回答by user2915097
why not use the official Java images, or the alpine Java, and just put in your Dockerfile
为什么不使用官方 Java 映像或 alpine Java,然后将其放入您的 Dockerfile
FROM java
FROM java
or
或者
FROM anapsix/alpine-java
FROM anapsix/alpine-java
? You have a functional Java installed and can do whatever you want.
? 您已经安装了一个功能强大的 Java,可以为所欲为。
See
看
http://hub.docker.com/search/?isAutomated=0&isOfficial=0&page=1&pullCount=0&q=java&starCount=0
http://hub.docker.com/search/?isAutomated=0&isOfficial=0&page=1&pullCount=0&q=java&starCount=0
for some Java from the docker hub
对于来自 docker hub 的一些 Java
You should read the good links provided by jonrsharpe
您应该阅读 jonrsharpe 提供的良好链接
回答by paulscott56
The container is a single contained entity. All changes that you make to it are essentially lost when you quit and restart it. There are 2 solutions to his though:
容器是单个包含的实体。当您退出并重新启动它时,您对其所做的所有更改基本上都会丢失。他的解决方案有两种:
- Do it properly, and add java to a RUN apt-get line in your Dockerfile, OR
- (Bad bad bad) Add it and hope your host never goes down.
- 正确操作,并将 java 添加到 Dockerfile 中的 RUN apt-get 行,或者
- (坏坏坏)添加它并希望您的主机永远不会出现故障。
Depending on what you want (Ubuntu or a container to run a Java app), you should either use the method in 1. or create a new Dockerfile that grabs FROM Java8 base image.
根据您的需求(Ubuntu 或运行 Java 应用程序的容器),您应该使用 1. 中的方法或创建一个新的 Dockerfile 来获取 Java8 基础映像。
回答by Rambler
You will have to commit the updated Image after installing Ubuntu.Try the following after installing java on the running container :
安装 Ubuntu 后,您必须提交更新后的图像。在运行的容器上安装 java 后,请尝试以下操作:
docker ps -l #get current container ID , let's sat it is "container_id"
Then :
然后 :
docker commit container_id ubuntu_with_java
It would create a new Image with name "ubuntu_with_java" .
它将创建一个名为 "ubuntu_with_java" 的新图像。