Unable to add git repo in Mix for alpine elixir

I am trying to build docker with the following Dockerfile

FROM elixir:1.8.2-alpine AS builder

WORKDIR /afterglowcode
COPY . /afterglowcode

ENV USER www-data
ENV GROUP www-data
RUN addgroup -S www-data && adduser -S www-data -G www-data

RUN apk add --no-cache git

RUN git config --global url."https://github.com/".insteadOf "git://github.com/"

RUN apk add --update bash && rm -rf /var/cache/apk/*

RUN export $(cat .env | xargs -0) && \
    mix local.hex --force && \
    mix local.rebar --force

RUN export $(cat .env | xargs -0) && mix deps.get

RUN export $(cat .env | xargs -0) && mix release

My mix.exs

defp deps do
    [
      {:phoenix, "~> 1.3.0"},
      {:phoenix_pubsub, "~> 1.0"},
      {:postgrex, ">= 0.14.0", override: true},
      {:phoenix_html, "~> 2.6"},
      {:ecto, "~> 3.1"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:gettext, "~> 0.11"},
      {:cors_plug, "~> 1.2"},
      {:ja_serializer, "~> 0.14.0"},
      {:sql_dust, path: 'web/modules/sql_dust'},
      {:ecto_enum, "~> 1.2"},
      {:cowboy, "~> 1.0"},
      {:oauth2, "~> 2.0"},
      {:joken, "~> 1.1"},
      {:libsodium, "~> 0.0.3"},
      {:keccakf1600, "~> 0.0.1"},
      {:libdecaf, "~> 0.0.1"},
      {:flasked, "~> 0.4"},
      {:bodyguard, "~> 1.0.0"},
      {:httpoison, "~> 0.11.1"},
      {:csv, "~> 2.1.1"},
      {:secure_random, "~> 0.5"},
      {:ex_aws, "~> 2.0"},
      {:ex_aws_s3, "~> 2.0.2"},
      {:sweet_xml, "~> 0.6.0"},
      {:bamboo, "~> 0.8.0"},
      {:bamboo_smtp, "~> 1.4.0"},
      {:distillery, "~> 2.0", runtime: false},
      {:jason, "~> 1.1"},
      {:cachex, git: "https://github.com/whitfin/cachex.git"},
      {:quantum, "~> 2.3"},
      {:timex, "~> 3.0"},
      {:oban, "~> 0.2"},
      {:mariaex, "0.9.1", override: true},
      {:db_connection, "~> 2.0", override: true},
      {:ecto_sql, "~> 3.1.0"},
      {:plug_cowboy, "~> 1.0"},
      {:mustache, "~> 0.3.0"},
      {:numerix, "~> 0.5.1"},
      {:hackney, github: "benoitc/hackney", override: true},
      {:gen_smtp, "~> 0.14.0", override: true}
    ]
  end

Error message

* Getting cachex (https://github.com/whitfin/cachex.git)
fatal: unable to access 'https://github.com/whitfin/cachex.git/': Could not resolve host: github.com
** (Mix) Command "git --git-dir=.git fetch --force --quiet --progress" failed
The command '/bin/sh -c export $(cat .env | xargs -0) && mix deps.get' returned a non-zero code: 1

Where is this run? Seems like it can’t access GitHub which is an error condition.

I’ve had this issue before, completely randomly from what I can tell.

The only fix I could come up with was to set the docker network to host, explicitly, when calling the build step.

--network="host"

No idea what causes it.