Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug phoenix application which running with docker?

I'm trying to use IEx.pry in index action from a controller, but doesn't work, I required IEx previously.

 defmodule Registering.DriverController do
   require IEx
   use Registering.Web, :controller
   ....
 end

 def index(conn, _params) do
   drivers = Repo.all(Driver)
   IEx.pry
   ...
 end

when I run docker-compose run web iex -S mix phx.server and reload index router, the iex console doesn't show the debuggin action.

This is my Dockerfile:

FROM elixir:latest

MAINTAINER Your Name <email>

RUN mix local.hex --force

RUN mix archive.install --force https://github.com/phoenixframework/archives/raw/master/phx_new.ez

RUN mix local.rebar --force

WORKDIR /app

And this is my docker-compose.yml:

web:
  build: .
  ports:
    - "4000:4000"
  command: mix phx.server
  environment:
    - MIX_ENV=dev
    - PORT=4000
  volumes:
    - .:/app
  links:
    - db
db:
  image: postgres
  environment:
    - POSTGRES_USER=postgres
    - POSTGRES_PASSWORD=postgres
    - POSTGRES_HOST=db
like image 985
Lorem Avatar asked Jun 03 '26 06:06

Lorem


1 Answers

use docker exec to attach to bash and run your custom iex session. for example:

docker exec -it NAME bash

like image 63
Farshid Ashouri Avatar answered Jun 05 '26 01:06

Farshid Ashouri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!