[英]How to run jar file using docker file in docker container
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 我写了用于运行jar文件的docker文件,它没有创建日志文件,以查看下面的控制台是我的docker文件
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"]
要仅在docker中运行myapp.jar(例如,避免在主机上安装Java),可以运行:
docker run -v `pwd`:/mnt java:8 java -jar /mnt/myapp.jar
The exec form of CMD
doesn't know what redirection is, that's a shell feature. CMD
的exec形式不知道重定向是什么,这是shell的功能。
Either use stdout for logging. 使用stdout进行日志记录。
CMD ["java","-jar","/real_estate_false.jar"]
If you really need a log file in the container, run the command in a shell 如果您确实需要容器中的日志文件,请在外壳中运行命令
CMD ["sh", "-c", "java -jar /real_estate_false.jar > var/log/jar.log"]
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 我建议进一步阅读fluentd可用的选项
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
<source>
@type forward
port 24224
</source>
<match **>
@type file
path /fluentd/log/events
append true
</match>
Are you married to the Oracle JDK? 您是否已与Oracle JDK结婚? The following Dockerfile would be considerable simpler: 以下Dockerfile会相当简单:
FROM openjdk:8
ADD target/demo-1.0.jar /opt/demo/demo-1.0.jar
CMD ["java","-jar","/opt/demo/demo-1.0.jar"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.