Building Play App as Docker image, remapping port

I’m trying to build my Play application into a docker container thats exposed on port 8080. ie. Requests to the docker container on port 8080 hit my play application.

I’m having trouble doing this. I was thinking I could do it by either mapping Docker port 8080 to the internal port 9000, but I can’t figure out how to do this with the sbt plugin. All I can do is change the exposed port using

  • How to setup dinghy for docker on Ubuntu 16.04?
  • Conditional fig configuration for dev needs
  • Docker, web app static files. Best practices?
  • How can I make an overlay network in docker without using docker-machine commands
  • Docker + supervisord: how to initialize services (mongo & elasticmq)?
  • Docker containers having trouble exposing ports to host on Mac
  • dockerExposedPorts := Seq(8080)
    

  • Error pushing image via docker registry v2 api
  • python logger in docker is not working
  • Docker, ipc resources and '--privilaged' option
  • wrapping DB in docker image
  • install local docker registry on centos 7
  • Docker machine in Mac OS X
  • 2 Solutions collect form web for “Building Play App as Docker image, remapping port”

    sbt-docker only builds the docker image. Exposing a port is correct, but you still have to connect it to the host network.

    For that you have to start the container and provide the correct mapping.

    docker run -p 9000:8080 ... yourImage ...
    

    You have two options. First one is to start the play app with the default port 9000 and when running your container use Docker port mapping to redirect from port 8080 outside of the container to port 9000 inside of the container:

    docker run -p 8080:9000 yourimage
    

    Option two is to to edit your application.conf and change the production port to be 8080:

    # production
    play.server.http.port = "8080"
    

    after having done it, change the dockerExposedPorts:

    dockerExposedPorts := Seq(8080)
    

    Note, that it will still run on port 9000 in the development mode (activator run).

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.