Project Icon

docker-phoenix

Elixir和Phoenix版本管理的容器化解决方案

docker-phoenix为Elixir和Phoenix框架提供容器化开发环境,解决版本冲突问题。基于Debian Bullseye镜像,项目提供完整工具链和文档,支持Visual Studio Code的Dev Containers。集成PostgreSQL数据库,并附带详细配置指南,适用于多项目开发和长期维护。

A Containerized Dev Environment for Elixir and the Phoenix Framework

Introduction

A dockerized development environment to work on Elixir and Phoenix framework projects while keeping the host environment pristine.

This project was conceived to deal with the issues of running different Elixir and Phoenix versions and supporting the development and maintenance of apps built with different Elixir and Phoenix versions.

Maybe you are working on multiple different projects, built with different versions of the Phoenix framework, or you are working on a long-lived Elixir or Phoenix project. In either case you are likely to hit a version conflict. Phoenix and Elixir are still young and evolving which is great - but some of the changes will likely break your application code. This repository aims to make things easier for you by giving you a straightforward path in swapping out your Elixir and Phoenix environment.

Notable Changes

  • Switch to Bullseye base image This is a potentially breaking change if you are using this image / repository as a base for your own customized images. We're switching from the upstream Alpine images to Debian Bullseye images, since most build tools and libraries, as well as the Erlang documentation are not included in the Alpine stream. Since the primary focus of this repository is to give developers easy access to the entire toolchain to build their Elixir/Phoenix applications with minimal requirements on the host, and as much of an optimal out-of-the-box dev experience with VSCode, we've decided that we'd rather have full toolchains and documentation over smaller image sizes.

  • **Docker Phoenix 1.7.10 ** The default database for the compose stack and devcontainer is now PostgreSQL 16

  • Docker Phoenix 1.7.5 The image now includes the build-base package by default to support compile-time dependencies like bcrypt for mix phx.gen.auth

  • #1d570c14007b7750da776e0b6bd2b7568ec67de5 We've switched the default branch of the repository from master to main. Please update your local repository refs!

  • Docker Phoenix 1.6.15 We are currently in the process of switching to Alpine Linux based images, which are significantly smaller (~150MB vs 1.7GB). Expect the next release to make -alpine the new default for the dev environments. As a result, you will need to rebuild your VSCode dev containers and your application code.

  • Docker Phoenix 1.6.13 Starting with this version, we've switched the Docker image hosted at Docker Hub (docker pull nicbet/phoenix:1.6.13) to M1 Mac, i.e., linux/arm64/v8 architecture. If you are developing on an Intel machine, you will need to build the docker image on your platform to get started run make docker-image.

Getting Started

As of December 2022, we recommend using the Visual Studio Dev Containers approach over the command line. See below for details.

Visual Studio Code (Dev Containers)

Setting up a brand-new project

If you are using a recent version of Visual Studio Code with the Dev Containers extension, we highly recommend going this route for a much improved development experience out of the box.

  1. Use Degit to quickly clone this project as a scaffold for your new project, for example an app called hello_world.

    npx degit nicbet/docker-phoenix#1.7.12 hello_world
    
  2. Open the hello_world folder in Visual Studio Code

  3. When asked, select Reopen in container. Visual Studio code will create a complete application stack including a PostgreSQL database, and mount your local ./app folder as the root folder for the development environment.

  4. After initialization of your dev environment finishes, open the Terminal tab in Visual Studio Code.

  5. Create your new Phoenix application with the following command (note the .!):

    mix phx.new . hello_world
    
  6. As the mix command runs, you will see your Visual Studio Code file explorer populate with the files of your new phoenix app. All these files are available outside your development environment in the ./app folder.

Note: You don't need to use degit. Alternatively, you can clone this repository and remove the .git folder manually.

Configuring the Database Connection

Both, the docker-compose stack started with the docker-compose.yml file included with this repository and the Visual Studio Code Dev Containers stack define a service called db for running a PostgreSQL database that is available to the main application container via the hostname db. By default Phoenix assumes that you are running a database locally. In order to use the db service with your application you will need to modify your Phoenix config and point Ecto to the database host.

To use the included database with your phoenix application you will need to modify the Ecto configuration config/dev.exs and point it to the DB container:

# Configure your database
config :test, Test.Repo,
  adapter: Ecto.Adapters.Postgres,
  hostname: "db",
  username: "postgres",
  password: "postgres",
  # ...
  pool_size: 10

Running your Application

To start you application in development mode you will first need to change your Phoenix configuration to bind the phx.server to 0.0.0.0, so that the container exposes the phx.server to the host network.

To bind the phx.server to all interfaces, edit your config/dev.exs file and set the endpoint listen address to 0.0.0.0:

config :hello_world, HelloWorldWeb.Endpoint,
  http: [ip: {0, 0, 0, 0}, port: 4000],
  ...

From the VSCode terminal you can run the Phoenix application server with:

mix phx.server

Once the startup is completed, your app will be available at http://localhost:4000

Using the Command Line instead of Dev Containers

After cloning the repository, you can use the included ./run, ./mix, ./npm, and ./yarn scripts to execute commands in the development environment described by included docker-compose.yml file. For instance, running ./mix phx.new . hello_world would generate a new phoenix application called hello_world. Similarly to the Visual Studio Code Dev Containers approach, your project files will be locally stored in the ./app container which is mounted to /app inside the development environment.

The instructions for changing the database connection and bind address as described above apply here as well.

To run any command inside the dev container, you can use the ./run script and pass the command and its arguments.

./run iex -S mix

Building the image for your platform

You can locally build the container image with the included Makefile:

make docker-image

Usage with an existing project

You can use this project to dockerize the development environment for an existing project. Follow the steps above, but instead of initializing a new application with mix phx.new, copy your existing project code to the ./app subdirectory. This will make your existing code available in the dockerized dev environment.

Contributing

This project is intended to be a safe, welcoming space for collaboration. Contributors are expected to adhere to the Contributor Covenant code of conduct. We recommend reading the contributing guide as well.

License

Docker Phoenix is available as open source under the terms of the GNU Public License v3.

Contributors

Docker Phoenix is built by members of the Open Source community, including:

apenney, cruisemaniac, homanchou, tmr08c, jacknoble, ravloony, asifaly ,ajmeese7, restlessronin

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

吐司

探索Tensor.Art平台的独特AI模型,免费访问各种图像生成与AI训练工具,从Stable Diffusion等基础模型开始,轻松实现创新图像生成。体验前沿的AI技术,推动个人和企业的创新发展。

Project Cover

SubCat字幕猫

SubCat字幕猫APP是一款创新的视频播放器,它将改变您观看视频的方式!SubCat结合了先进的人工智能技术,为您提供即时视频字幕翻译,无论是本地视频还是网络流媒体,让您轻松享受各种语言的内容。

Project Cover

美间AI

美间AI创意设计平台,利用前沿AI技术,为设计师和营销人员提供一站式设计解决方案。从智能海报到3D效果图,再到文案生成,美间让创意设计更简单、更高效。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号