jswny

jswny

Hello everyone, I recently redesigned my entire deployment process for Phoenix apps based on Docker. I really like the strategy that I came up with and it’s working very well for me so far. I have a new VPS which I’ve vowed to only install Docker on, and this strategy is perfect for my goal.

In addition, my strategy is optimized for:

  • Running multiple apps on the same server
  • Being compatible with deployment of any other kind of app (not just Elixir/Phoenix)
  • Compilation completely separate from deployment so you can compile anywhere and deploy anywhere else

In the interest of helping others who might be struggling with the same thing, I’ve documented my entire process in a Gist. I would love to contribute to this wonderful community on what seems to be one of the most popular difficulties when it comes to Phoenix (deployment).

Please let me know if you have any thoughts. The post is here: Flexible Dockerized Phoenix Deployments.

Showing Posts 1 to 10

juhalehtonen

juhalehtonen

Hey! Just wanted to drop a quick note saying thanks for the write-up :slight_smile:

I followed the guide last night and everything seemed to work fine. I’ll perform some tests and alterations and will comment back further if I find anything specific to talk about.

jswny

jswny OP

Awesome! I’m Glad that you found the guide useful! I look forward to hearing your comments :slight_smile:

jswny

jswny OP

Just added another section on how to (kind of) hot upgrade the server container without touching the database container. This should be pretty useful to people using this kind of Docker configuration because being able to swap out containers individually when your app changes is a huge advantage.

nelson687

nelson687

Hey, I’ve been following this guide, but can’t make it work, I’m not using a database, just using a genserver to store data, so I skipped all the DB parts, also don’t want to use nginx. So I got to this point:

docker run --rm -it --name myapp-server -p 5000:5000 myapp-release foreground

and everything seems to be fine, I can see some logs from the app, but I can’t access from the browser, tried 0.0.0.0:5000 but can’t see anything, the only thing I added was: ENV PORT=4000 in Dockerfile.run, as I’m using phoenix 1.3, is there anything I’m missing?

idi527

idi527

the only thing I added was: ENV PORT=4000

So you are listening on 4000, but mapping -p 5000:5000 5000 to 5000? I don’t think that would work.

You can try changing either ENV PORT=4000 to ENV PORT=5000 or -p 5000:5000 to -p 4000:5000 (which would map tcp port 4000 in the container to port 5000 on the host).

nelson687

nelson687

Tried with that and rebuilt everything but still can’t access, is it right to try to access on my mac on 0.0.0.0:5000 ? I’ve changed the phoenix port to 5000 by adding ENV PORT=5000 and using the param -p 5000:5000 on docker run. I’m running this on my mac as a host machine.

idi527

idi527

I’ve followed the tutorial up to

docker run --rm -it --name myapp-server -p 5000:5000 myapp-release foreground

and it hasn’t mentioned that you should uncomment one of the lines below in order for “phoenix in a release” to work.

config/prod.exs

# ## Using releases
#
# If you are doing OTP releases, you need to instruct Phoenix
# to start the server for all endpoints:
#
config :phoenix, :serve_endpoints, true # <--- here
#
# Alternatively, you can configure exactly which server to
# start per endpoint:
#
#     config :test, TestWeb.Endpoint, server: true

Otherwise cowboy is not started. AFAIK it is not uncommented by default so as not to start cowboy on any other task like phx.digest.

Maybe that’ll help you. Don’t forget to re./build.sh the release.


EDIT: server: true is mentioned later in section 7. :+1:

emoragaf

emoragaf

Thanks for putting this guide up. I have some questions about other options in the release building process, and the docker-compose setup.

  1. Have you looked at generating the release tarball using multi-stage builds rather than your current build script?

  2. Shouldn’t the db service in the docker-compose be using a volume for the data in case the container dies?

OvermindDL1

OvermindDL1

If accessing it locally you instead want http://127.0.0.1:5000 for note.

jswny

jswny OP

Thanks for reading! That should work. If you have ENV PORT=5000 in your Dockerfile.run and you are running the container with -p 5000:5000 you should be able to access it from your host machine on localhost:5000 or 127.0.0.1:5000.

I would make sure that you completely rebuild everything by deleting all of the images first just so you know Docker isn’t using any cached stages. You can do this with docker rmi myapp-build myapp-release.

However, I think at that stage in the guide you still won’t be able to run the server because you haven’t changed the config which is not explained until step 7. I will try and update the guide accordingly so that running things manually comes after that.

Where Next? Top

Trending in Guides/Tuts Top

rogach
I’ve spent some time understanding how to do hot code reloading with releases built using mix release, and here I’d like to detail the st...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews