Phoenix in a docker dev environment - generated code can't be saved from VSCode

38 Views Asked by At

I am new to phoenix, and am trying to setup a project using Docker on WSL. I have the project running, and I can make changes just fine. The issue occurs when using one of the Phoenix generators, whenever I try to edit a generated file I have no permission to save it, since it was created from inside the container.

I have worked with Docker before, but mainly for PHP. I understand that I need to create a user that matches my host user. However, when I try this, I get errors that mix has no permission to read certain files, like from the _build directory for example. I am new and probably completely missing something. Here are my base Dockerfile docker-compose.yml and entrypoint.sh, without the user created:

Dockerfile:

FROM hexpm/elixir:1.16.2-erlang-26.2.2-alpine-3.19.1    

RUN apk add --no-cache git 

RUN mkdir /app
COPY . /app
WORKDIR /app

RUN mix local.hex --force
RUN mix deps.get && mix deps.compile

CMD /app/entrypoint.sh

docker-compose.yml:


services:
  phoenix:
    build:
      context: .
    volumes:
      - ./:/app
    environment:
      DB_USER: user
      DB_PASSWORD: secret
      DB_DATABASE: vrn
      DB_PORT: 3306
      DB_HOST: db
    ports:
      - 4000:4000
    depends_on:
      - db
  db:
    image: mysql:8.3
    environment:
      MYSQL_ROOT_PASSWORD: rootsecret
      MYSQL_DATABASE: vrn
      MYSQL_USER: user
      MYSQL_PASSWORD: secret
    restart: always
    volumes:
      - mysql:/var/lib/mysql
volumes:
  mysql:

entrypoint.sh:

mix ecto.create
mix ecto.migrate
mix phx.server

I have tried creating a user and group to match my host user at the beginning of the Dockerfile, but I am sort of new to it and have probably completely messed that up.

0

There are 0 best solutions below