collins icon indicating copy to clipboard operation
collins copied to clipboard

allow listen address to be configured alongside port

Open cburroughs opened this issue 8 years ago • 5 comments

This is useful if cases where collins runs on a node with multiple interfaces, or behind a proxy.

cburroughs avatar Mar 25 '16 15:03 cburroughs

LGTM! Could you add this to the Dockerfile's entrypoint as well?

byxorna avatar Mar 25 '16 17:03 byxorna

I don't think the Dockerfile has a precedent for configuration like this. For example the port is just hard coded as -Dhttp.port=9000``and that is relied upon by theEXPOSE` statement.

cburroughs avatar Mar 25 '16 17:03 cburroughs

@cburroughs it would be nice to have listen.address explicitly set to 0.0.0.0, but totally not necessary for this PR.

byxorna avatar Mar 25 '16 18:03 byxorna

@cburroughs maybe this is because I'm running docker 1.10.0, but I was able to add the following to the dockerfile and it respected the environment variable.

$ git diff Dockerfile
diff --git a/Dockerfile b/Dockerfile
index 32b7e9f..72caa23 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -30,7 +30,8 @@ WORKDIR /opt/collins
 # You probably will want to override these configs in production
 COPY conf/docker conf/

+ENV PORT 9000
+
 # expose HTTP, JMX
-EXPOSE 9000 3333
+EXPOSE $PORT 3333
 CMD ["/usr/bin/java","-server","-Dconfig.file=/opt/collins/conf/production.conf","-Dhttp.port=9000","-Dlogger.file=/opt/collins/conf/logger.xml","-Dnetworkaddress.cache.ttl=1","-Dnetworkaddress.cache.negative.ttl=1","-Dcom.sun.management.jmxremote","-Dcom.sun.management.jmxremote.port=3333","-Dcom.sun.management.jmxremote.authenticate=false","-Dcom.sun.management.jmxremote.ssl=false","-XX:MaxPermSize=384m","-XX:+CMSClassUnloadingEnabled","-cp","/opt/collins/lib/*","play.core.server.NettyServer","/opt/collins"]
-

And then when I built and inspected the container, I got port 9000 exposed:

$ docker inspect will-collins
[
    {
        "Id": "sha256:bf93647bd4735d032e9814a44090ec2fc0bb4a8849cadfc8f654af39adc890f0",
        "RepoTags": [
            "will-collins:latest"
        ],
        "RepoDigests": [],
        "Parent": "sha256:42c864b87c4b0aa9475a88fa1b78d3ddecfe4164dc0b7ffcbde711fbf3585a93",
        "Comment": "",
        "Created": "2016-03-28T15:47:49.588022328Z",
        "Container": "c9f22977a400f761729b282c2086c46af0503e7d03d5d46cf03e93d73096c91f",
        "ContainerConfig": {
            "Hostname": "e5c68db50333",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "3333/tcp": {},
                "9000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre",
                "JAVA_VERSION=8u72",
                "JAVA_DEBIAN_VERSION=8u72-b15-1~bpo8+1",
                "CA_CERTIFICATES_JAVA_VERSION=20140324",
                "PORT=9000"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) CMD [\"/usr/bin/java\" \"-server\" \"-Dconfig.file=/opt/collins/conf/production.conf\" \"-Dhttp.port=9000\" \"-Dlogger.file=/opt/collins/conf/logger.xml\" \"-Dnetworkaddress.cache.ttl=1\" \"-Dnetworkaddress.cache.negative.ttl=1\" \"-Dcom.sun.management.jmxremote\" \"-Dcom.sun.management.jmxremote.port=3333\" \"-Dcom.sun.management.jmxremote.authenticate=false\" \"-Dcom.sun.management.jmxremote.ssl=false\" \"-XX:MaxPermSize=384m\" \"-XX:+CMSClassUnloadingEnabled\" \"-cp\" \"/opt/collins/lib/*\" \"play.core.server.NettyServer\" \"/opt/collins\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:42c864b87c4b0aa9475a88fa1b78d3ddecfe4164dc0b7ffcbde711fbf3585a93",
            "Volumes": {
                "/opt/collins/conf/solr/cores/collins/data": {}
            },
            "WorkingDir": "/opt/collins",
            "Entrypoint": null,
            "OnBuild": [],
            "Labels": {}
        },
..... <more stuff here>

So I think we could set the port using an environment variable in the Dockerfile, and make all of the scripts used in the container respect that variable to change the port that gets used. Not sure if it's worth doing or not though, since at runtime it could be changed. Maybe this is a job for docker's build-args, but I haven't used them before so I don't have a good idea of how they work yet.

william-richard avatar Mar 28 '16 15:03 william-richard

I'd not use the script with the Dockerfile. I personally never used those scripts and in general try to avoid using 'vendor scripts' to bring up my services. I think it's fine to provide them here for convenience, but wouldn't change the Dockerfile to use it.

So IMO, this can get merged. Is there something else blocking it?

discordianfish avatar Oct 28 '16 17:10 discordianfish