Skip to content

bo5o/mise-env-docker-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mise-env-docker-compose

A mise plugin that automatically loads environment variables from your Docker Compose configuration into your shell environment.

Overview

This plugin resolves your Docker Compose configuration and extracts environment variables defined in your services, making them available in your local development environment. This is useful when you want to match the environment variables used in your containerized services without manually duplicating them.

Installation

Add this plugin to your mise configuration:

[plugins]
env-docker-compose = "https://github.com/bo5o/mise-env-docker-compose"

[env]
_.source = "env-docker-compose"

Configuration

The plugin supports several configuration options to control which environment variables are loaded:

Basic Usage

Load all environment variables from all services:

[env]
_.env-docker-compose = {}

Filter by Services

Load environment variables only from specific services:

[env]
_.env-docker-compose = { services = ["web", "api"] }

Filter by Variables

Load only specific environment variable names:

[env]
_.env-docker-compose = { variables = ["DATABASE_URL", "REDIS_URL"] }

Host Replacement

Replace service references with localhost ports (useful for connecting to containerized services from your host):

[env]
_.env-docker-compose = { replace_hosts = true }

When replace_hosts is enabled, environment variable values like postgres:5432 will be replaced with localhost:5433 (using the published port from your Docker Compose configuration).

How It Works

  1. The plugin runs docker compose config --format json to get the parsed configuration
  2. It extracts environment variables from the environment section of each service
  3. It optionally filters by service names and variable names
  4. If replace_hosts is enabled, it replaces service:port references with localhost:published_port
  5. The resulting environment variables are made available in your shell

Example

Given a docker-compose.yml:

---
services:
  web:
    image: myapp
    environment:
      DATABASE_URL: postgres:5432
      API_KEY: secret123
    ports:
      - "3000:3000"

  postgres:
    image: postgres:15
    environment:
      POSTGRES_PASSWORD: password
    ports:
      - "5433:5432"

With this configuration:

[env]
_.env-docker-compose = { services = ["web"], replace_hosts = true }

Your shell environment will have:

  • DATABASE_URL=localhost:5433 (replaced postgres:5432 with localhost:5433)
  • API_KEY=secret123

Requirements

  • mise installed
  • Docker and Docker Compose installed
  • Valid Docker Compose configuation in your project

About

A mise plugin that loads environment variables from docker compose configuration

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages