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.

  • How to get Shared file system for docker containers running on different hosts?
  • Trying to find reason for 500 error when running a Django site in Nginx
  • Unable to ping docker container
  • using docker for quick switching iojs version
  • Docker search command with criteria shows inconsistent results
  • OSI Layer Model for Docker?
  • 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?

  • Connecting to a running docker container - differences between using ssh and running a command with “-t -i” parameters
  • Dockerfile RUN creates a fat layer even with cleanup
  • Symfony3 fetch wrong data from database
  • is it advisable to have multiple applications in a single docker image
  • Setting up CD for a Ruby on Rails project with Bitbucket Pipelines and Docker
  • Use environment variables in docker
  • 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.