How to run jar file using docker file in docker container

后端 未结 3 1052
鱼传尺愫
鱼传尺愫 2021-01-24 06:08

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 &         


        
相关标签:
3条回答
  • 2021-01-24 06:49

    To just run myapp.jar in docker (e.g. to avoid installing java on the host) you can just run:

    docker run -v `pwd`:/mnt java:8 java -jar /mnt/myapp.jar
    
    0 讨论(0)
  • 2021-01-24 06:56

    The exec form of CMD doesn't know what redirection is, that's a shell feature.

    Either use stdout for logging.

    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
    
    0 讨论(0)
  • 2021-01-24 07:03

    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"]
    
    0 讨论(0)
提交回复
热议问题