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.

  • Docker: Error while executing 'docker run hello-world' command
  • How to link docker containers?
  • Why does docker prompt “Permission denied” when backing up the data volume?
  • Grafana setup on docker
  • Uninstall weave docker
  • docker login unknown shorthand flag: 'e'
  • 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?

  • search on my Auth+TLS private docker registry
  • Access a webserver inside a docker container from outside
  • Docker compose: ensure volume mounted before running CMD
  • Storing secret env variables as separate data container in Docker
  • ElasticBeanstalk Docker host network mode
  • dial unix /var/run/docker.sock: no such file or directory after upgrading to lxc-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.