Error with DATABASE_URL when deploying Phoenix application to Heroku

Hi, I’m following to deploy using Heroku containers.

Here’s the example repo:

When I push to heroku I get following error:

Apples-MacBook-Pro:hello ivanbisevac$ git push heroku master
Enumerating objects: 83, done.
Counting objects: 100% (83/83), done.
Delta compression using up to 8 threads
Compressing objects: 100% (75/75), done.
Writing objects: 100% (83/83), 97.06 KiB | 6.93 MiB/s, done.
Total 83 (delta 4), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: === Fetching app code
remote: === Building web (Dockerfile)
remote: Sending build context to Docker daemon  368.6kB
remote: Step 1/25 : FROM elixir:1.9.0-alpine AS build
remote: 1.9.0-alpine: Pulling from library/elixir
remote: e7c96db7181b: Pulling fs layer
remote: c306444e2774: Pulling fs layer
remote: 4b80324f258b: Pulling fs layer
remote: e7c96db7181b: Verifying Checksum
remote: e7c96db7181b: Download complete
remote: 4b80324f258b: Verifying Checksum
remote: 4b80324f258b: Download complete
remote: e7c96db7181b: Pull complete
remote: c306444e2774: Verifying Checksum
remote: c306444e2774: Download complete
remote: c306444e2774: Pull complete
remote: 4b80324f258b: Pull complete
remote: Digest: sha256:bd6e03f00f57a121f6f31374d693e9027ce6053e25700be4d7c64f83dd249a56
remote: Status: Downloaded newer image for elixir:1.9.0-alpine
remote:  ---> 7a6d28e4b511
remote: Step 2/25 : RUN apk add --update build-base npm git
remote:  ---> Running in 244929b60841
remote: fetch
remote: fetch
remote: (1/31) Upgrading musl (1.1.20-r4 -> 1.1.20-r5)
remote: (2/31) Installing binutils (2.31.1-r2)
remote: (3/31) Installing libmagic (5.36-r1)
remote: (4/31) Installing file (5.36-r1)
remote: (5/31) Installing gmp (6.1.2-r1)
remote: (6/31) Installing isl (0.18-r0)
remote: (7/31) Installing libgomp (8.3.0-r0)
remote: (8/31) Installing libatomic (8.3.0-r0)
remote: (9/31) Installing libgcc (8.3.0-r0)
remote: (10/31) Installing mpfr3 (3.1.5-r1)
remote: (11/31) Installing mpc1 (1.0.3-r1)
remote: (12/31) Installing libstdc++ (8.3.0-r0)
remote: (13/31) Installing gcc (8.3.0-r0)
remote: (14/31) Installing musl-dev (1.1.20-r5)
remote: (15/31) Installing libc-dev (0.7.1-r0)
remote: (16/31) Installing g++ (8.3.0-r0)
remote: (17/31) Installing make (4.2.1-r2)
remote: (18/31) Installing fortify-headers (1.0-r0)
remote: (19/31) Installing build-base (0.5-r1)
remote: (20/31) Installing nghttp2-libs (1.35.1-r1)
remote: (21/31) Installing libssh2 (1.9.0-r1)
remote: (22/31) Installing libcurl (7.64.0-r3)
remote: (23/31) Installing expat (2.2.8-r0)
remote: (24/31) Installing pcre2 (10.32-r1)
remote: (25/31) Installing git (2.20.1-r0)
remote: (26/31) Upgrading musl-utils (1.1.20-r4 -> 1.1.20-r5)
remote: (27/31) Installing c-ares (1.15.0-r0)
remote: (28/31) Installing http-parser (2.8.1-r0)
remote: (29/31) Installing libuv (1.23.2-r0)
remote: (30/31) Installing nodejs (10.14.2-r0)
remote: (31/31) Installing npm (10.14.2-r0)
remote: Executing busybox-1.29.3-r10.trigger
remote: OK: 235 MiB in 51 packages
remote: Removing intermediate container 244929b60841
remote:  ---> c32d9dd1e1ab
remote: Step 3/25 : RUN mkdir /app
remote:  ---> Running in 1421ee00b856
remote: Removing intermediate container 1421ee00b856
remote:  ---> 99aace19d0bf
remote: Step 4/25 : WORKDIR /app
remote:  ---> Running in e1cb3f87b4d0
remote: Removing intermediate container e1cb3f87b4d0
remote:  ---> c37e5c3877f2
remote: Step 5/25 : RUN mix local.hex --force &&     mix local.rebar --force
remote:  ---> Running in 35ced8130ede
remote: * creating /root/.mix/archives/hex-0.20.1
remote: * creating /root/.mix/rebar
remote: * creating /root/.mix/rebar3
remote: Removing intermediate container 35ced8130ede
remote:  ---> afa2e665d580
remote: Step 6/25 : ENV MIX_ENV=prod
remote:  ---> Running in f5b1950ab144
remote: Removing intermediate container f5b1950ab144
remote:  ---> 8e416fc55c15
remote: Step 7/25 : COPY mix.exs mix.lock ./
remote:  ---> 2c89dc19046c
remote: Step 8/25 : COPY config config
remote:  ---> 5ac08e894b10
remote: Step 9/25 : RUN mix deps.get
remote:  ---> Running in 161800382fd6
remote: ** (RuntimeError) environment variable DATABASE_URL is missing.
remote: For example: ecto://USER:PASS@HOST/DATABASE
remote:     (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
remote:     (stdlib) erl_eval.erl:449: :erl_eval.expr/5
remote:     (stdlib) erl_eval.erl:126: :erl_eval.exprs/5
remote:     (elixir) lib/code.ex:240: Code.eval_string/3
remote:     (mix) lib/mix/config.ex:158: anonymous fn/2 in Mix.Config.__import__!/2
remote:     (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
remote:     (mix) lib/mix/config.ex:157: Mix.Config.__import__!/2
remote: The command '/bin/sh -c mix deps.get' returned a non-zero code: 1
remote: Verifying deploy...
remote: !	Push rejected to serene-tor-13468.
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ''

Have you set up database on your Heroku app? ‘DATABASE_URL is missing’ means that you haven’t exported the environment variable. You probably didn’t add a database as addon on Heroku.

If you use postgres, here is the tutorial how to do it:

1 Like

Yes, that is covered in this part:

To prove that database url is set I tried (I changed the values of course):

Apples-MacBook-Pro:hello ivanbisevac$ heroku config
=== serene-tor-13468 Config Vars
DATABASE_URL:    postgres://
POOL_SIZE:       18

Seems like heroku is not exposing those variables in the build time. Probably heroku.yml from the tutorial is wrong.

Hmm. The issue could be related to docker. Try use this buildpack instead:

That’s ok, but my question is not about buildpack deploy, but container one. Whole point is that there is Phoenix documentation how to deploy which doesn’t work.

1 Like

think the issue will be solved if you complete these steps:


Make sure the environment variables are created in Heroku, then add the following two lines to the top of the Dockerfile: