DkM
DkM

Reputation: 800

AWS EB, Play Framework and Docker: Application Already running

I am running a Play 2.2.3 web application on AWS Elastic Beanstalk, using SBTs ability to generate Docker images. Uploading the image from the EB administration interface usually works, but sometimes it gets into a state where I consistently get the following error:

Docker container quit unexpectedly on Thu Nov 27 10:05:37 UTC 2014: Play server process ID is 1 This application is already running (Or delete /opt/docker/RUNNING_PID file).

And deployment fails. I cannot get out of this by doing anything else than terminating the environment and setting it up again. How can I avoid that the environment gets into this state?

Upvotes: 2

Views: 883

Answers (2)

punkdata
punkdata

Reputation: 885

@dkm was having the same issue with my dockerized play app. I package my apps as standalone for production using '$ sbt clean dist` commands. This produces a .zip file that you can deploy to some folder in your docker container like /var/www/xxxx.

Get a bash shell into your container: $ docker run -it <your image name> /bin/bash

Example: docker run -it centos/myapp /bin/bash

Once the app is there you'll have to create an executable bash script I called mine startapp and the contents should be something like this:

Create the script file in the docker container:

$ touch startapp && chmod +x startapp

$ vi startapp

Add the execute command & any required configurations:

#!/bin/bash

/var/www/<your app name>/bin/<your app name> -Dhttp.port=80 -Dconfig.file=/var/www/pointflow/conf/<your app conf. file>

Save the startapp script then from a new terminal and then you must commit your changes to your container's image so it will be available from here on out:

Get the running container's current ID:

$ docker ps

Commit/Save the changes

$ docker commit <your running containerID> <your image's name>

Example: docker commit 1bce234 centos/myappsname

Now for the grand finale you can docker stop or exit out of the running container's bash. Next start the play app using the following docker command:

$ docker run -d -p 80:80 <your image's name> /bin/sh startapp

Example: docker run -d -p 80:80 centos/myapp /bin/sh startapp

Run docker ps to see if your app is running. You see something similar to this:

CONTAINER ID        IMAGE                   COMMAND              CREATED             STATUS              PORTS                NAMES
19eae9bc8371        centos/myapp:latest   "/bin/sh startapp"   13 seconds ago      Up 11 seconds       0.0.0.0:80->80/tcp   suspicious_heisenberg

Open a browser and visit your new dockerized app

Hope this helps...

Upvotes: 1

Usman Ismail
Usman Ismail

Reputation: 18649

Sounds like you may be running into the infamous Pid 1 issue. Docker uses a new pid namespace for each container, which means first process gets PID 1. PID 1 is a special ID which should be used only by processes designed to use it. Could you try using Supervisord instead of having playframework running as the primary processes and see if that resolves your issue? Hopefully, supervisord handles Amazon's termination commands better than the play framework.

Upvotes: 5

Related Questions