Phoenix server doesn't render css and images with Docker

Viewed 139

I'm new to Elixir and Phoenix, and having to work in CI/CD environment I'm trying to figure out how to use Phoenix with Docker.

I've tried various tutorials and videos out there, many of them doesn't work, but those who do work, they have the same result.

enter image description here

Phoenix server doesn't seems to find some resources (the assets folder?).

But inside my Dockerfile I'm copying the entire app folder, and I can confirm that /assets is inside the container by attaching to it.

Dockerfile:

FROM elixir:alpine

RUN apk add --no-cache build-base git

WORKDIR /app

RUN mix local.hex --force && \
    mix local.rebar --force

COPY . .

RUN mix do deps.get, deps.compile

CMD ["mix", "phx.server"]

Docker-compose

version: '3.6'
services:
  db:
    environment:
      PGDATA: /var/lib/postgresql/data/pgdata
      POSTGRES_PASSWORD: postgres
      POSTGRES_USER: postgres
      POSTGRES_HOST_AUTH_METHOD: trust
    image: 'postgres:11-alpine'
    restart: always
    volumes:
      - 'pgdata:/var/lib/postgresql/data'
  web:
    build: .
    depends_on:
      - db
    environment:
      MIX_ENV: dev
    env_file:
      - .env
    ports:
      - '4000:4000'
    volumes:
      - .:/app
volumes:
  pgdata:

Steps I'm doing to create the containers and running the server:

docker-compose build
docker-compose run web mix ecto.create
docker-compose up

The database is created successfully in the db container. What can be happening here?

Sorry if it's straightforward, I don't use Docker for a while and I still didn't understood Phoenix boilerplate completely.

If you know some good resources about Docker and CI/CD pipelines with Phoenix, I also appreciate so I can study it.

1 Answers

You also need to build the assets. npm install --prefix assets This needs to be done after after mix deps.get but can be done after the mix deps.compile which isn't really needed. You can start the server after mix deps.get and it will compile the deps and your app automatically.

Related