Docker - Premature Exit - Status 0

I was successfully able to deploy a phoenix application using the aws elastic beanstalk interface.

I then tried to deploy a processing application to a different aws elastic beanstalk interface.
The docker files are almost identical, except for the fact that for phoenix, I do a simple:

CMD MIX_ENV=prod mix phx.server

and all is fine.

For the processing application however, I tried doing:
CMD MIX_ENV=prod iex -S mix and this is not working.

I get a deployment error stating that the docker quitted unexpectingly. Checking docker ps -a reveals that it exited with status 0, which indicates that for some reason or the other, docker thinks the container is finished running and exits accordingly. When I change the line to CMD ['bash'] and then I enter the docker and manually run MIX_ENV=prod iex -S mix it works just fine. The entire app works and runs as required.

I concluded that there must be some extra options required that phx.server provides. I also looked into how distillery seems to handle foreground persistence. I eventually did the following:

CMD MIX_ENV=prod iex --erl "-noshell -noinput +Bd" -S mix run

inspired from FOREGROUNDOPTIONS="-noshell -noinput +Bd"

Now the deployment works, the docker is up and running but my app is not working.

I do not need distillery for my project, so I would not like to add it in just for the sake of being able to run a release as foreground.

1 Like

On slack channel, David was so kind to point out the issue.

CMD MIX_ENV=prod mix run --no-halt does the trick

David Antaramian @ajwah Why are you calling iex -S mix?
I think you really want mix run --no-halt


Depends on what you mean by “need”. Using a release has at least one major advantage: no lag after startup. Mix loads code lazily, so the first several requests that hit your service after it boots are gonna be a lot slower because Mix will need to go load the code necessary to service them. Releases know exactly what code you need and make sure it’s loaded up front.