DoMD provides seamless Docker integration, allowing you to run commands in isolated containers with automatic environment detection. This document covers all aspects of using Docker with DoMD.
Create a .dodocker
file in your project root to configure Docker execution:
# .dodocker
test:
image: python:3.9-slim # Base image to use
description: Run Python tests # Optional description
workdir: /app # Working directory in container
volumes: # Volume mappings
~/.cache/pip:/.cache/pip # Cache directory
.:/app # Mount current directory
environment: # Environment variables
PYTHONPATH: /app
Run commands with Docker (automatically detected from .dodocker):
# Run tests in Docker
poetry run domd run test
# Force local execution (bypass Docker)
poetry run domd run --no-docker test
# List available Docker commands
poetry run domd list --docker
You can configure multiple commands with different settings:
# .dodocker
format:
image: python:3.9-slim
description: Format Python code
volumes:
.:/app
command: "black ." # Override default command
test:
image: node:16-slim
description: Run JavaScript tests
volumes:
.:/app
/app/node_modules # Anonymous volume for dependencies
environment:
NODE_ENV: test
For more complex setups, you can use Docker Compose:
# docker-compose.yml
version: '3.8'
services:
app:
build: .
volumes:
- .:/app
environment:
- PYTHONPATH=/app
working_dir: /app
Then reference it in your .dodocker
file:
test:
compose: docker-compose.yml
service: app
command: pytest tests/
DoMD handles volume mounting with smart defaults:
/app
by defaulttest:
image: python:3.9-slim
volumes:
.:/app # Mount current directory
~/.cache/pip:/.cache/pip # Cache directory
/tmp:/tmp # Mount system temp
/data # Anonymous volume
You can pass environment variables to Docker containers:
# Pass environment variables from host
DOMD_ENV=production poetry run domd run test
# Or define them in .dodocker
test:
environment:
NODE_ENV: test
DEBUG: 1
DATABASE_URL: postgres://user:pass@db:5432/mydb
For sensitive data, use an environment file:
test:
env_file: .env.test
environment:
- NODE_ENV=test
To debug Docker-related issues:
# Show Docker commands being executed
DOMD_DEBUG=1 poetry run domd run test
# Get shell in container with the same environment
poetry run domd shell test
# View container logs
docker logs <container_id>
# Inspect container configuration
docker inspect <container_id>
# View running processes
docker top <container_id>
latest
python:3.9-slim
instead of just python
-slim
or -alpine
variants when possible.dockerignore
to exclude sensitive filesIf you see permission errors with mounted volumes:
ARG USER_ID=1000
ARG GROUP_ID=1000
RUN groupadd -g $GROUP_ID appuser && \
useradd -u $USER_ID -g appuser -m appuser
USER appuser
If a command works locally but fails in Docker:
For network-related problems:
# Check network connectivity inside container
docker run --rm --network host busybox ping google.com
# Inspect container network
docker network inspect bridge
If you encounter issues:
DOMD_DEBUG=1
for verbose output