本文介绍了在Docker映像中安装Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次尝试创建docker映像,我希望有人可以帮助我。我的Dockerfile大致如下所示:

This is my very first try to create a docker image and I'm hoping someone can help me out. My Dockerfile looks roughly like this:

FROM mybaseimage:0.1
MAINTAINER ...

ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
RUN sed 's/main$/main universe/' -i /etc/apt/sources.list

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update

RUN apt-get install -y openjdk-7-jre && apt-get clean &&\
             mkdir temp_dir  &&   cd temp_dir && \
             ${JAVA_HOME}/bin/jar -xvf somejar.jar  &&\
             cd ..
ENTRYPOINT ["somescript.sh"]

基本上,我只安装Java,因此可以扩展jar文件。运行生成文件时,出现以下错误:

Basically I'm only installing Java so I can expand a jar file. When I run my makefile I get the following error:

/ bin / sh:1:/ usr / lib / jvm / java-7-openjdk-amd64:权限被拒绝

/bin/sh: 1: /usr/lib/jvm/java-7-openjdk-amd64: Permission denied

我一直在尝试遵循以下示例:

I've been trying to follow this example:https://registry.hub.docker.com/u/barnybug/openjdk-7-jre/dockerfile/

非常感谢

编辑:评论中的每个请求都是我的makefile:

per request in the comment here is my makefile:

DOCKER_REGISTRY=registry.mycompany.com
DOCKER_IMAGE=appimage-myapp
DOCKER_TAG=3.0

SUDO=

ARCHIVE_NAME=$(DOCKER_IMAGE):$(DOCKER_TAG)
  REPO_ARCHIVE_NAME=$(DOCKER_REGISTRY)/$(ARCHIVE_NAME)
  BASE_IMAGE_ARCHIVE=$(DOCKER_IMAGE)_$(DOCKER_TAG).tar.gz

all: $(BASE_IMAGE_ARCHIVE)

.PHONY: docker_image

docker_image: Dockerfile
    $(SUDO) docker build -t $(ARCHIVE_NAME) .

$(BASE_IMAGE_ARCHIVE): docker_image
  $(SUDO) docker tag -f $(ARCHIVE_NAME) $(REPO_ARCHIVE_NAME)
  $(SUDO) docker push $(REPO_ARCHIVE_NAME)
  $(SUDO) docker save $(ARCHIVE_NAME) | gzip -c > $@
  $(SUDO) docker rmi $(REPO_ARCHIVE_NAME)

我与

make docker_image SUDO=sudo


推荐答案

我能够通过以下步骤安装 OpenJDK-8 (摘自)。我的 Dockerfile 继承自 phusion / baseimage-docker ,它基于 Ubuntu 16.04 LTS

I was able to install OpenJDK-8 via the steps below (taken from here). My Dockerfile inherits from phusion/baseimage-docker, which is based on Ubuntu 16.04 LTS.

# Install OpenJDK-8
RUN apt-get update && \
    apt-get install -y openjdk-8-jdk && \
    apt-get install -y ant && \
    apt-get clean;

# Fix certificate issues
RUN apt-get update && \
    apt-get install ca-certificates-java && \
    apt-get clean && \
    update-ca-certificates -f;

# Setup JAVA_HOME -- useful for docker commandline
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME

要安装 OpenJDK-7 ,您可能需要先添加

To install OpenJDK-7 instead, you may need to prepend

add-apt-repository ppa:openjdk-r/ppa

使第一步变为

# Install OpenJDK-7
RUN add-apt-repository ppa:openjdk-r/ppa && \
    apt-get update && \
    apt-get install -y openjdk-7-jdk && \
    apt-get install -y ant && \
    apt-get clean;

我希望这会有所帮助。

这篇关于在Docker映像中安装Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 05:53