nikolis

nikolis

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.

Showing Posts 1 to 7

NobbZ

NobbZ

Your compose file isn’t set up to do any portmapping.

Please use the port directive for your web service.

nikolis

nikolis OP

thanks @NobbZ

Changing the docker-compose.yml to

version: '3.5'       

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

or (because of nework_mode: host)

version: '3.5'       

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

seem to make no difference !

the docker documentation also mentions:

ports

Expose ports.

Note
Port mapping is incompatible with network_mode: host

egze

egze

Maybe server: true is missing from the Endpoint config?

NobbZ

NobbZ

Oh, i haven’t realized the network mode, as I usually prefer explicit portmapping rather than polluting the host systems network randomly…

nikolis

nikolis OP

Thank you this was actually what was missing. I took some time because now I have different problems but thats probably because the server is running.

nikolis

nikolis OP

Thanks for your response but let me ask why do consider that polluting ? And can you please just give me a scenarion that this practice is problematic ? This is a genunie question as I am new to docker and chiefly using it as a container to avoid not in my computer issues and in general for easeay when shipping the app.

NobbZ

NobbZ

If one starts everything within the hosts network, one needs to consider ports already when building the containers and it is hard to spin the same container multiple times.

By using explicit portmapping, you can spin the very same container, just mapping different ports.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews