Deploying an Elixir Release using Docker on Render.com
Tags: elixir, beginners, docker, webdev
Published: 2021-11-04 11:51:47

---
title: Deploying an Elixir Release using Docker on Render.com
published: true
description: Deploy an Elixir Release, using Docker, on Render.com
tags: elixir, beginners, docker, webdev
//cover_image: https://direct_url_to_image.jpg
canonical_url: https://blog.miguelcoba.com/deploying-an-elixir-release-using-docker-on-rendercom
series: Deploying Elixir
---

I'm going to show you how to deploy our Elixir Release to render.com. We'll use our  [Docker image](https://blog.miguelcoba.com/deploying-a-phoenix-16-app-with-docker-and-elixir-releases).

## Prepare Elixir Release for deploying to render.com

We only need to do a single change to our `runtime.exs` file. Add the `url:` line to the 

```elixir
  config :saturn, SaturnWeb.Endpoint,
    url: [host: System.get_env("RENDER_EXTERNAL_HOSTNAME") || "localhost", port: 80],
    http: [
      # Enable IPv6 and bind on all interfaces.
      # Set it to  {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
      # See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
      # for details about using IPv6 vs IPv4 and loopback vs public addresses.
      ip: {0, 0, 0, 0, 0, 0, 0, 0},
      port: String.to_integer(System.get_env("PORT") || "4000")
    ],
    secret_key_base: secret_key_base
```

I am creating a branch named `render-deployment` and committing all these changes to it:

```bash
git checkout -b render-deployment
git add .
git commit -m "Config for render.com"
git push -u origin render-deployment
```

## Create and configure your render.com account

Create an account in render.com and log in. We are going to create two services, one for the database and one for the Elixir Release. We must be sure that both services are created in the *same* region so that they share the same private network and can communicate and establish connections using their assigned network names. If we fail to do this, you'll see errors in the logs saying that the database domain name is non-existant (:nxdomain error). 

For this article, I'm going to put both in the `Oregon, USA` region. Be sure to use the same one.


### Create the Database

Create a database service by clicking the `New +` button on the dashboard:

![Create a new Database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xnmvbgymot5h4of8kml1.png)

Select one name for this service (I'm using Saturn DB) and ensure the `Oregon, USA` region is selected. Leave the other fields to their defaults and select the `Free` plan. Then click the `Create Database` to provision this service.

![Configure Database](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aol0jtt5l4p26q48lspx.png)

In the next page you'll see the details of the database. We need to copy one value from here, the connection string that we'll use for the `DATABASE_URL` environment variable when we create the Elixir Release service.

Click the copy button on the *Internal Connection String* 

![Copy Internal Connection String](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vozanc9htfb3q10j6dft.png)
 
### Create the Web Service

Let's create a *Web Service* with the `New +` button:


![Create a Web Service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6cjmpvkx5qjixkuid9xl.png)
 
You'll need to connect your GitHub or GitLab account:


![Connect your GitHub or GitLab account](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3xfpsd11n3qvdbc17r0q.png)
 
and select the repository you want to deploy:

![Select repository to deploy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yekvm89x2nstyejua6r7.png)

Let's configure it. Set a name for your service (I'm using Saturn here). You'll see that the Dockerfile was detected and the Environment is preselected to `Docker`. Ensure you're using the `Oregon, USA` region, otherwise both services won't be able to connect each other. Select the branch you want to deploy (in my case is `render-deployment`) and select the *Free* plan.

![Configure Web Service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qe0zcoy3b5kkj014yn93.png)

```
mix phx.gen.secret
```

We need to add a couple of environment variables. 

![Create environment variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0hbwg78l7xdj1wlfaxji.png)
 
Create a `DATABASE_URL` and paste the value you copied from the *Internal Connection String* field in the Database service config page.

Then add another named `SECRET_KEY_BASE`. Run this command on the terminal and use the result as the value for it:

```bash
mix phx.gen.secret
```

![Environment variables created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/149pynlmysnvsnpac5tt.png)
 
You can now create the Web Service. You'll see the status of the provisioning and when it is ready you'll see a green `Live` button and a line on the logs saying that the Endpoint is listening for requests:

![Provisioning Web Service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nbtuqkwz3il7955cfng8.png)
 
If you click on the URL generated for your Web Service you'll see your Elixir Release app running on Render.com infrastructure:


![Elixir Release running on render.com](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zg5zu71vt9hqp6o9osvg.png)
 
## Running Migrations and connecting to the running instance

This is something I couldn't do so far. The UI render provides has no way to connect to the running container. One way to run the migrations would be:


1. Build the Elixir Release locally as shown [here](https://blog.miguelcoba.com/preparing-a-phoenix-16-app-for-deployment-with-elixir-releases) 
2. Copy the *External Connection String* from the database configuration page
3. Set a DATABASE_URL environment variable to that value
4. Run the `_build/prod/rel/saturn/bin/saturn eval "Saturn.Release.migrate"` command

## Source code

The  [source code](https://github.com/miguelcoba/saturn/tree/render-deployment)  for the saturn project is open source under the MIT license. Use the `render-deployment` branch.

## About

I'm [Miguel Cobá](https://miguelcoba.com). I write about Elixir, Elm, Software Development, and eBook writing.

- Follow me on [Twitter](https://twitter.com/MiguelCoba_)
- Subscribe to my [newsletter](https://newsletter.miguelcoba.com)
- Read all my articles on my [blog](https://blog.miguelcoba.com)
- Get my books:
    - [100 Elixir Tips](https://store.miguelcoba.com/l/100elixirtips) [FREE]
    - [Deploying Elixir](https://store.miguelcoba.com/l/deployingelixir) [FREE]
    - [Deploying Elixir: Advanced Topics](https://store.miguelcoba.com/l/advancedtopics)
    - [eBook Writing Workflow for Developers](https://store.miguelcoba.com/l/ebookwriting)