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

  • Execute script inside docker container which is folder different than WORKDIR
  • How do I clean up cached partial images from a broken Docker pull?
  • Connect to docker containers with just service name and task slot?
  • https is not working on httpd docker container
  • Not able to install the gem “rmagick” with docker
  • Error Docker deployment in Amazon Elastic Beanstalk - Docker container quit unexpectedly
  • dockerExposedPorts := Seq(8080)
    

  • Meteor, docker and SSL on localhost
  • How can I use dynamic linking in a Docker image based on busybox?
  • Isolated Docker containers and resource limiting
  • Docker: save internal hd contents
  • Why does running docker with ProcessBuilder cause a hang?
  • ASP.NET 5.0 beta 8 in Docker doesn't start
  • 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.