nikolis

nikolis

Poblem listeing on port when running phoenix through docker

Hello fellas I am trying to deploy my phoenix app using distillery releases and docker I have been following tthis tutorial to get started.

What I have been up so far is this
prod.exs:

 config :greek_coin, GreekCoinWeb.Endpoint,
   http: [port: 80],       
   url: [host: "localhost"],       
   force_ssl: [rewrite_on: [:x_forwarded_proto]],
   https: [
     :inet6,               
     port: 443,
     cipher_suite: :strong,
     otp_app: :greek_coin, 
     keyfile: "/path/to/key.txt",
     certfile: "/path/to/cert.cert"
   ]

Docker file only slightly modified from the one in the turorial

# Set this to true if this release is not a Phoenix app
ARG SKIP_PHOENIX=false
# If you are using an umbrella project, you can change this
# argument to the directory the Phoenix app is in so that the assets
# can be built
ARG PHOENIX_SUBDIR=.

ENV SKIP_PHOENIX=${SKIP_PHOENIX} \
    APP_NAME=${APP_NAME} \
    APP_VSN=${APP_VSN} \
    MIX_ENV=${MIX_ENV}

# By convention, /opt is typically used for applications
WORKDIR /opt/app

# This step installs all the build tools we'll need
RUN apk update && \
  apk upgrade --no-cache && \
  apk add --no-cache \
    nodejs \
    yarn \
    git \
    build-base && \
  mix local.rebar --force && \
  mix local.hex --force



# This copies our app source code into the build container
COPY . .

RUN mix do deps.get, deps.compile, compile 

# This step builds assets for the Phoenix app (if there is one)
# If you aren't building a Phoenix app, pass `--build-arg SKIP_PHOENIX=true`
# This is mostly here for demonstration purposes
RUN if [ ! "$SKIP_PHOENIX" = "true" ]; then \
  cd ${PHOENIX_SUBDIR}/assets && \
  yarn install && \
  yarn deploy && \
  cd - && \
  mix phx.digest; \
fi

RUN \
  mkdir -p /opt/built && \
  mix distillery.release --verbose && \
  cp _build/${MIX_ENV}/rel/${APP_NAME}/releases/${APP_VSN}/${APP_NAME}.tar.gz /opt/built && \
  cd /opt/built && \
  tar -xzf ${APP_NAME}.tar.gz && \
  rm ${APP_NAME}.tar.gz
# From this line onwards, we're in a new image, which will be the image used in production
FROM alpine:${ALPINE_VERSION}

# The name of your application/release (required)
ARG APP_NAME=greek_coin

RUN apk update && \
    apk add --no-cache \
      bash \
      openssl-dev \
      openssl\
      erlang-crypto


ENV REPLACE_OS_VARS=true \
    APP_NAME=${APP_NAME}

WORKDIR /opt/app

COPY --from=builder /opt/built .
RUN echo $DATABASE_HOST
RUN echo $DATABASE_USER
RUN echo $DATABASE_PASS
RUN echo $DATABASE_NAME
EXPOSE 80

CMD trap 'exit' INT; /opt/app/bin/${APP_NAME} foreground

make file

.PHONY: help
                               
APP_NAME ?= `grep 'app:' mix.exs | sed -e 's/\[//g' -e 's/ //g' -e 's/app://' -e 's/[:,]//g'`
APP_VSN ?= `grep 'version:' mix.exs | cut -d '"' -f2`
BUILD ?= `git rev-parse --short HEAD`

help:
    @echo "$(APP_NAME):$(APP_VSN)-$(BUILD)"
    @perl -nle'print $& if m{^[a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

build: ## Build the Docker image
    docker build --build-arg APP_NAME=$(APP_NAME) \
        --build-arg APP_VSN=$(APP_VSN) \
        -t $(APP_NAME):$(APP_VSN)-$(BUILD) \
        -t $(APP_NAME):latest .

run: ## Run the app in Docker  
    docker run --env-file config/docker.env \
        --expose 80 -p 80:80 \ 
        --expose 443 -p 443:443 \
        --network host \       
        --rm -it $(APP_NAME):latest

docker-compose.yml

version: '3.5'

services:
  web:
    image: "greek_coin:latest"
    network_mode: host
    env_file:
      - docker.env

docker.env

HOSTNAME="localhost"
PORT=80
LANG=en_US.UTF-8  
REPLACE_OS_VARS=true           
ERLANG_COOKIE=greek_coin

Then I procced with the make build which outputs

Successfully built c244749bcf14
Successfully tagged greek_coin:0.1.1-114f7e3
Successfully tagged greek_coin:latest

And then I am running with docker-compose up
which only shows the following warning

Recreating greek_coin_web_1 ... done
Attaching to greek_coin_web_1
web_1  | warning: :simple_one_for_one strategy is deprecated, please use DynamicSupervisor instead
web_1  |   (elixir 1.10.4) lib/supervisor.ex:604: Supervisor.init/2
web_1  |   (stdlib 3.13) supervisor.erl:301: :supervisor.init/1
web_1  |   (stdlib 3.13) gen_server.erl:417: :gen_server.init_it/2
web_1  |   (stdlib 3.13) gen_server.erl:385: :gen_server.init_it/6
web_1  |   (stdlib 3.13) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Thing is that in my docker-compose.yml I am using the network_mode: host
using this parameter I got rid of the complains about database connection I had earlier but further more my expectation is that I should be able to access my app just by visiting localhost in my host machine. But this is not the case the container is runnig without any further output but I cannot access it through localhost. What do I miss ?

Any help or references that might help me understand my problem are greatly appriciated
Thanks in advance.

Marked As Solved

egze

egze

Maybe server: true is missing from the Endpoint config?

Where Next?

Popular in Questions Top

chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39523 209
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36432 110
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement