如何使用docker文件在docker容器中运行jar文件

如何使用docker文件在docker容器中运行jar文件

本文介绍了如何使用docker文件在docker容器中运行jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了Docker文件来运行jar文件,它不会创建日志文件,看到下面的控制台是我的docker文件

 从ubuntu 
运行apt-get update&& \
apt-get upgrade -y&&& \
apt-get install -y software-properties-common&& \
add-apt-repository ppa:webupd8team / java -y&&& \
apt-get update&& \
echo oracle-java8-installer shared / accepted-oracle-license-v1-1 select true | / usr / bin / debconf-set-choices&& \
apt-get install -y oracle-java8-installer&& \
apt-get clean
VOLUME / temp
运行apt-get install -y vim
添加real_estate_false.jar /real_estate_false.jar
COPY real_estate_false_lib / real_estate_false_lib
COPY资源/资源
COPY testxml / testxml
CMD [java, - jar,/ real_estate_false.jar,>,var / log / jar.log ]


解决方案

为什么要创建日志文件>内部容器?配置将更加灵活。



以下示例被设计,但演示如何收集来自所有容器的日志记录事件。我建议您进一步阅读中提供的选项。



示例



首先运行流畅的收集日志事件

  mkdir log 
docker run -d --name fluentd -p 24224 :24224 -v $ PWD:/ fluentd / etc -v $ PWD / log:/ fluentd / log -e FLUENTD_CONF = log.conf fluent / fluentd

现在运行一个容器来创建要记录的事件:

  docker run  - -log-driver = fluentd ubuntu echo hello world 

示例配置将日志事件发送到输出日志文件

 ├──log 
│└──events.20160901.b53b670f22298bbcb
└──日志。 conf



log.conf



 <信源> 
@type转发
端口24224
< / source>

< match **>
@type file
path / fluentd / log / events
append true
< / match>






其他



你是否结婚到Oracle JDK?以下Docker文件将会相当简单:

  FROM openjdk:8 
添加目标/ demo-1.0.jar / opt /demo/demo-1.0.jar
CMD [java, - jar,/ opt / demo / demo-1.0.jar]


I write the docker file for run the jar file and it does not create the log file for see the console below is my docker file

From ubuntu
RUN apt-get update && \
    apt-get upgrade -y && \
    apt-get install -y  software-properties-common && \
    add-apt-repository ppa:webupd8team/java -y && \
    apt-get update && \
    echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
    apt-get install -y oracle-java8-installer && \
    apt-get clean
VOLUME /temp
RUN apt-get install -y vim
ADD real_estate_false.jar /real_estate_false.jar
COPY real_estate_false_lib /real_estate_false_lib
COPY resources /resources
COPY testxml /testxml
CMD ["java","-jar","/real_estate_false.jar",">","var/log/jar.log"]
解决方案

Why are you creating a logging file inside the container? Configuring a logging driver would be more flexible.

The following example is contrived, but demonstrates how logging events from all your containers could be collected. I suggest reading further into the options available from fluentd

Example

First run fluentd within a container to collect log events

mkdir log
docker run -d --name fluentd -p 24224:24224 -v $PWD:/fluentd/etc -v $PWD/log:/fluentd/log -e FLUENTD_CONF=log.conf fluent/fluentd

Now run a container that creates an event to be logged:

docker run --log-driver=fluentd ubuntu echo hello world

The sample configuration sends log events to an output log file

├── log
│   └── events.20160901.b53b670f22298bbcb
└── log.conf

log.conf

<source>
  @type  forward
  port  24224
</source>

<match **>
   @type file
   path         /fluentd/log/events
   append       true
</match>


Additional

Are you married to the Oracle JDK? The following Dockerfile would be considerable simpler:

FROM openjdk:8
ADD target/demo-1.0.jar /opt/demo/demo-1.0.jar
CMD ["java","-jar","/opt/demo/demo-1.0.jar"]

这篇关于如何使用docker文件在docker容器中运行jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:08