appropriate / docker-jetty

Formerly the location of the Docker official image for Jetty
https://registry.hub.docker.com/_/jetty/
46 stars 46 forks source link

How to use with mongo session manager #56

Closed tholu closed 7 years ago

tholu commented 7 years ago

I'm trying to configure mongo (running on the docker host) as a session manager for jetty, but if fails because it cannot connect. Does anybody have a working example of how this can be achieved?

I'm getting this exception:

 java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused (Connection refused)
    at com.mongodb.DBPort._open(DBPort.java:206)
    at com.mongodb.DBPort.go(DBPort.java:94)
    at com.mongodb.DBPort.go(DBPort.java:75)
    at com.mongodb.DBPort.findOne(DBPort.java:129)
    at com.mongodb.DBPort.runCommand(DBPort.java:138)
    at com.mongodb.DBTCPConnector.fetchMaxBsonObjectSize(DBTCPConnector.java:414)
    at com.mongodb.Mongo.getMaxBsonObjectSize(Mongo.java:537)
    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:237)
    at com.mongodb.DBApiLayer$MyCollection.createIndex(DBApiLayer.java:347)
    at org.eclipse.jetty.nosql.mongodb.MongoSessionIdManager.<init>(MongoSessionIdManager.java:187)
    at org.eclipse.jetty.nosql.mongodb.MongoSessionIdManager.<init>(MongoSessionIdManager.java:175)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.eclipse.jetty.util.TypeUtil.construct(TypeUtil.java:580)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:793)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1239)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1144)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.set(XmlConfiguration.java:466)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:411)

I actually try to overwrite the config like that in my Dockerfile:

FROM jetty:9.3-jre8-alpine
EXPOSE 8080

ADD /target/myapplication.war /var/lib/jetty/webapps/ROOT.war
RUN mkdir -p /var/lib/jetty/config/
ADD /jetty.xml /var/lib/jetty/jetty.xml

RUN java -jar "$JETTY_HOME/start.jar" --add-to-startd=nosql --approve-all-licenses

CMD ["java","-Djava.io.tmpdir=/tmp/jetty","-jar","/usr/local/jetty/start.jar", "--debug", "/var/lib/jetty/jetty.xml"]

It seems that the config done in /var/lib/jetty/jetty.xml is ignored, where I set the ServerAddress to a different host. Any pointers?

tholu commented 7 years ago

I got it working by adjusting the Dockerfile like this:

FROM jetty:9.3-jre8-alpine
EXPOSE 8080

ADD /target/myapplication.war /var/lib/jetty/webapps/ROOT.war
ADD /jetty.xml /usr/local/jetty/etc/jetty-nosql.xml

RUN java -jar "$JETTY_HOME/start.jar" --add-to-startd=nosql --approve-all-licenses

CMD ["java","-Djava.io.tmpdir=/tmp/jetty","-jar","/usr/local/jetty/start.jar", "--debug"]

It now replaces the local config file in /usr/local/jetty/etc/jetty-nosql.xml. You also have to make sure that mongo listens on the right ip address or on 0.0.0.0.

md5 commented 7 years ago

Glad you figured it out. I would probably recommend a containerized Mongo in this case instead of running it on the Docker host.

tholu commented 7 years ago

@md5 Yes you're right, but then you still have to change the mongo URL from 127.0.0.1 to mongo (or how you name the container), and figuring out how to do this was the hard step here (at least for me).