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

  • Docker + ELK stack taking up more space than it should
  • run batch in wordpress docker container
  • Docker stops immediately upon running - EOF error
  • How to access JIRA Software files in a docker image?
  • How can I check when was a docker image pulled?
  • Does capitrano conflict with docker?
  • dockerExposedPorts := Seq(8080)

  • docker push to non-TLS registry
  • how can docker containers have a different flavor than the host
  • Pull a local image to run a pod in Kubernetes
  • Create AWS::ECR::Repository resource by Cloudformation
  • Mixed binary log by default
  • CoreOS: fleetctl status shows service inactive, while container is up
  • 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.