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.

  • Will copying 'images' folder between machines be used to move images between docker hosts?
  • how to set ulimit / file descriptor on docker container the image tag is phusion/baseimage-docker
  • Oracle11g database long startup in docker container
  • Replacing a particular instance on AWS Elastic BeanStalk?
  • Map ports so you can access docker running apps from OSX host
  • Installing Python 3 Docker Ubuntu error command 'x86_64-linux-gnu-gcc
  • 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?

  • Using Docker Environment Variable inside of Java
  • Creating a swarm cluster with Docker for Mac
  • Docker scaling containers on a single host
  • Can docker compose skip build if the image is present?
  • How to bundle install a local path gem with docker?
  • Creating docker containers on Windows
  • 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.