Welcome to the modern era of development, where efficiency and simplicity reign supreme. If you’re working with Elixir and Phoenix, you’ll want to streamline your workflow by setting up a containerized development environment using Docker. This guide will help you do just that!
What is Containerization?
Think of containerization as owning a magical box that organizes all your tools and ingredients for baking a cake. Instead of sifting through your entire kitchen for eggs, flour, and sugar, you simply open this box and find everything you need in one place – easily accessible and neatly arranged! In the context of Elixir Phoenix, Docker containers hold all your application components, ensuring they work seamlessly no matter where you are.
What You Gain from This Setup
- One-line Setup: With just the command
docker-compose up, you’re ready to roll! This command creates your database and runs all necessary pre-setup. - Developer-friendly: Changes made in the container are instantly reflected on your host machine and vice-versa.
- Fast Re-builds: The Dockerfile is optimized for caching, ensuring speedy rebuilds when you make changes.
- Simple Dependency Management: You don’t have to deal with troublesome dependencies; they’re all taken care of!
- No Hacks Needed: Enjoy a clean setup utilizing Elixir 1.9.4, compatible with Phoenix 1.4, along with the latest Postgres.
Step-by-Step Instructions
1. Prepare Your Project
Begin by copying the three crucial files to your existing Phoenix project:
- Dockerfile
- docker-compose.yml
- run.sh
2. Make run.sh Executable
Open a terminal and run the following command:
chmod +x run.sh
3. Configure Database Settings
Edit the database connection settings in your dev.exs and test.exs files. You can hard-code the credentials or define environment variable overrides like:
config :my_app, MyApp.Repo,
hostname: System.get_env("DB_HOST", "localhost"),
password: System.get_env("DB_PASS", "postgres")
4. Spin it Up!
Run the following command to launch your development environment:
docker-compose up
Usage
Running Tests
To execute tests, use either of the commands below:
docker-compose run web mix test
Or, for a faster startup, try:
docker-compose exec web mix test
Troubleshooting Tips
If you’re facing issues, here are a few ideas to help:
- Ensure your Docker installation is running correctly.
- Double check the file permissions for
run.sh. - Verify your database connection settings in
dev.exsandtest.exs. - If the application doesn’t start up properly, try stopping and then restarting the containers with
docker-compose downfollowed bydocker-compose up.
For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.
Conclusion
By following these straightforward steps, you can create a containerized development environment for your Elixir Phoenix application. Gone are the days of configuration headaches!
At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

