fly49
Hi, I am trying to get Phoenix app work using containers and elixir releases.
I succeeded to run my app in a single container and connect it to local postgres using dockerfile and command below:
Dockerfile:
FROM elixir:1.9.0-alpine AS build
# install build dependencies
RUN apk add --no-cache build-base npm git python
# prepare build dir
WORKDIR /app
# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
# set build ENV
ENV MIX_ENV=prod
# install mix dependencies
COPY mix.exs mix.lock ./
COPY config config
RUN mix do deps.get, deps.compile
# build assets
COPY assets/package.json assets/package-lock.json ./assets/
RUN npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
COPY priv priv
COPY assets assets
RUN npm run --prefix ./assets deploy
RUN mix phx.digest
# compile and build release
COPY lib lib
# uncomment COPY if rel/ exists
# COPY rel rel
RUN mix do compile, release
# prepare release image
FROM alpine:3.9 AS app
RUN apk add --no-cache openssl ncurses-libs
EXPOSE 4000
ENV PORT=4000 \
MIX_ENV=prod \
SHELL=/bin/bash
WORKDIR /app
RUN chown nobody:nobody /app
USER nobody:nobody
COPY --from=build --chown=nobody:nobody /app/_build/prod/rel/myapp ./
ENV HOME=/app
CMD ["bin/myapp", "start"]
Commands:
docker build -t test .
docker run \
--network=host \
-e DATABASE_URL=postgresql://postgres:postgres@localhost/myapp_dev \
-e SECRET_KEY_BASE=...some key... \
-e HOST=localhost \
test
But when I am trying to up two containers via docker-compose.yml
version: '3'
services:
PostgreSQL:
image: postgres
container_name: postgres
ports:
- 5433:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_INITDB_ARGS: "--encoding=UTF-8"
hostname: postgres
restart: always
user: root
elixir:
build:
context: .
dockerfile: Dockerfile
env_file:
- .env.list
ports:
- 4040:4000
container_name: elixir
volumes:
- .:/app
depends_on:
- PostgreSQL
.env.list:
DATABASE_URL=postgresql://postgres:postgres@postgres/myapp_prod
SECRET_KEY_BASE=... some key...
HOST=localhost
I am getting an error:
Creating postgres ... done
Creating elixir ... error
ERROR: for elixir Cannot start service elixir: OCI runtime create failed: container_linux.go:367: starting container process caused: exec: "bin/myapp": stat bin/myapp: no such file or directory: unknown
ERROR: Encountered errors while bringing up the project.
I suppose that docker-compose should just run elixir container with according dockerfile as just it happens with “docker run …”, but it seems that I get different container which doesn’t have bin/ directory for some reason. Am I missing something?
Trending in Questions
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
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
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
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
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 13 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
ambareesha7
Sure I’ll do it, thank you
Exadra37
Sorry for the delay in the reply but I have been away from Elixir for some months, does I am not aware how things are related to this.
I would suggest for you to open a new post with reproducible steps to replicate your issue and then people will jump in and try to help/guide you.
ambareesha7
Hey @Exadra37
As you said it’s merged but changes not working
Today I was preparing for docker deployment and for
mix phx.gen.release --dockercommand as suggested on Phoenix documentsUsed versions to generate: Elixir 1.13, Phoenix 1.6.6
The
nobodyvariable still being used in generated Dockerfile fileIs it expected behavior or it needs to be reported them on the PR?
pmangalakader
@fly49 It’s a straight-forward implementation and I’m using somewhat same pre-start scripts in multiple accounts and works like a charm. Due to NDA constraints, I’m unable to share them with you.
If you could create a new topic and post relevant logs, it would be easier for others also to help you.
fly49
Thank you for the answer! I got suck a the creating and migrating database on containers initialization, tried the trick from here, but it doesn’t work for me.. Could you recommend me something?
pmangalakader
@fly49 try this, the
chownworked for me:the directory
/home/user, theuserdirectory was owned byrootand hence, the error occurs.fly49
Exact as here
Exadra37
You need to share the exact dockerfile you are using, otherwise is not possible to understand whats going on.
fly49
@Exadra37
I succeeded to build an image from new dockerfile, with all boot logic in runtime.exs as you said, but when I try:
I get
Exadra37
Unfortunately it’s not a default.
It was introduced in Elixir 1.11 to solve the configuration issues that have plagued Elixir since the begin.
Think of this file not as runtime but instead as a boot time configuration file, because contrary to what the name
runtimeimplies it doesn’t allow to change configuration while your app is running, but it allows you to change configuration every time you boot your app.In my apps I move all configuration to this file as much as possible. Check the official docs here:
Secrets in Releases
For example
prod.secret.exsisn’t secure to use, because now you have your production secrets inside the release binary and production secrets MUST BE only present in the server running the app, otherwise you risk to leak the secrets in all the places were the release binary is handled. It’s easy to reverse engineer a binary and extract those secrets.Always require your secrets in
runtime.exswith the use of environment variables. This approach will keep your production secrets outside the release binary that you have built somewhere else.