Docker running nginx plus jar

I’m trying to run a docker container that contains both a java jar server and nginx in front of it to perform subdomain->port forwarding, and I don’t seem to be setting it up correctly.
This is my Dockerfile:

FROM java:8
RUN apt-get update
RUN apt-get -y install nginx
COPY theBigOwlServer.jar /data/server.jar
RUN rm -v /etc/nginx/nginx.conf
ADD nginx.conf /etc/nginx/
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80 8080
CMD java -jar /data/server.jar     
CMD service nginx start            #<--- line AAA

The java jar listens on ports 8080 and 8090. When I run this container with -p 80:80 -p 8080:8080, the jar just doesn’t seem to start. I don’t see any console output from it, and I can’t reach it from outside the container with curl localhost:8080. I can reach nginx on port 80, but requests that should be forwarding to the jar are coming back with an empty reply.

  • Is it safe to run docker container in production as root?
  • ERROR 1582 (42000) Incorrect parameter count in the call to native function 'FROM_UNIXTIME'
  • Concourse add file to docker image just once
  • Run DDL-script generated by Entity Framework does not create tables in Docker container
  • Docker error on an entrypoint script: “no such file or directory”
  • Docker workflow design with Jenkins on production
  • However, if I comment out line AAA, then the jar starts fine. It generates console output and curl localhost:8080 reaches it. How can I run nginx and the jar together?

  • Can't start docker
  • How to serve static content in a Node Express container with Docker?
  • Error while run Sphinx search service
  • Scripts within Python on current directory
  • How do you determine if a docker container is running on remote docker-machine or locally running in docker engine?
  • Building a docker image doesnt stop because of minecraft server continuing to run
  • 2 Solutions collect form web for “Docker running nginx plus jar”

    Docker containers are designed for single-process sandboxing, so only take one CMD argument. In this case it’s just picking up the last one in the file. If you need to run multiple prorcesses in a container (and sometimes it makes sense to do so) then use something like Supervisor to run your commands for you (so your CMD would run Supervisor). Then you get goodies like process watchdogs and such thrown in too.

    You could do something like:

    ENTRYPOINT sh -c 'service nginx start && java -jar /data/server.jar'

    I tried this out and it worked for me.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.