This template provides a streamlined development setup for Phoenix projects using Docker, eliminating the need to install Elixir, Phoenix, or PostgreSQL locally.
Standard tools are used to generate a new Phoenix project (through a throwaway docker container). Then a light-weight docker-compose setup is copied into the project. This allows both generation of new projects, and ongoing development, purely through Docker with no local dependencies.
- Complete Docker-based development environment
- PostgreSQL database setup and configuration
- Automatic environment configuration
- Hot code reloading
- Asset compilation (when needed)
- Database migration handling
- Docker
- Docker Compose
No other dependencies required - everything runs in containers!
- Clone this template:
git clone [email protected]:pix2D/phoenix-docker-template.git
- Create a new project:
cd phoenix-docker-template
./phx_new_docker.sh your_project_name
This will create your project in the parent directory.
- Start the development environment:
cd ../your_project_name
docker compose up -d
Note: it will take a while for the initial setup to finish. You can monitor the progress using docker compose logs -f
.
# Start containers in background
docker compose up -d
# View logs
docker compose logs
# Follow logs
docker compose logs -f
# Stop containers
docker compose down
# Rebuild containers
docker compose up -d --build
# Run mix commands
docker compose exec web mix help
docker compose exec web mix test
# Run shell in container
docker compose exec web sh
# Run iex in container
docker compose exec web iex
# Run Phoenix commands
docker compose exec web mix phx.routes
The template sets up a standard Phoenix project with some Docker-specific additions:
your_project/
├── docker/
│ ├── Dockerfile.dev # Development Dockerfile
│ └── entrypoint.sh # Container startup script
├── docker-compose.yml # Docker Compose configuration
├── .dockerignore # Docker ignore file
└── ... (standard Phoenix files)
If you need to add Node.js dependencies:
- Create
assets/package.json
if it doesn't exist - Add dependencies to package.json
- Rebuild the container:
docker compose up -d --build
The PostgreSQL database persists data in a Docker volume. To reset completely:
docker compose down -v # -v removes volumes
docker compose up -d # Recreates everything from scratch
To access the database directly:
docker compose exec db psql -U postgres
Check the logs:
docker compose logs
- Ensure the database container is running:
docker compose ps
- Check database logs:
docker compose logs db
- Access the container:
docker compose exec web sh
- Check the assets directory:
cd assets
npm install
This template is mainly made for personal use, but feel free to submit an issue if you run into a problem or have a suggestion and I'll consider it.