DEV Community

Discussion on: Development environment for Elixir + Phoenix with Docker and Docker-compose

Collapse
 
robert197 profile image
Robert

You should use either 2 containers, One for frontend one for backend or make use of multistage builds.
The problem is that nobody wants deploy the front-end code with all its node_modules folder. You have to build the front-end assets for prod environment and make sure the containers are tiny as possible.
Have a look on "staged" builds on docker docs. You can also use one docker file and reference the stages in docker compose. E.g. stage: development for prod you use production stage.

Collapse
 
hlappa profile image
Aleksi Holappa • Edited

What you said is valid, but for deployments to cloud infrastructure (dev, staging, production). On the up-coming article I'll be doing a multi-stage build with alpine images to keep the end result pretty tiny with only including some tooling required by BEAM and the application binary itself.

I just want to point out that this article is to help you to setup local development environment, not for deploying a small footprint image to cloud etc.

Collapse
 
robert197 profile image
Robert

First of all, by following the best practices of docker. An image should not have frontend and backend dependencies. It does not matter if its for local development environment or for non local environments.
Also docker is built to solve one big problem. The problem is called "it works on my machine". By defining different containers for local and non local you missuse power of docker.
The solution is to use 2 containers. One for front-end dependencies, one for backend and make use of multistage builds.
Doesn't matter if local or non local.
If you want i could make s pull request on your GitHub repo to show you how it works.
What do you think?

Greetings

Thread Thread
 
hlappa profile image
Aleksi Holappa • Edited

Well, if I use alpine based image on local development and on cloud deployments, how that does not solve the "it works on my machine" issue? I'm just curious.

I have one question, how I'm going to do rapid local development if I build the images locally with multistage Dockerfile? What happens to hot code reloading? Also, Elixir with Phoenix framework is SSR, so there is no separate frontend and backend as e.g. in Node and React. Nevertheless, you can separate the static assets and other browser rendered stuff and backend to own containers in cloud deployments, but on local environment I don't see the real benefit of it.

I opened the repo, you should be able to make a merge/pull request to it. You can find the link below, don't mind the naming of the repo. I'm waiting for MR!

gitlab.com/hlappa/url-shortener/

Thread Thread
 
sergio_101 profile image
sergio t. ruiz

I ended up finding this here: evolvingdev.io/phoenix-local-devel... ..

The trick is adding this:

    watchOptions: {
      poll: true
    },
Enter fullscreen mode Exit fullscreen mode

to your webpack.config.js.