|
| 1 | +#!/bin/bash |
| 2 | +# ============================================================================ |
| 3 | +# Podman Docker Compatibility Setup |
| 4 | +# ============================================================================ |
| 5 | +# Sets up Docker CLI compatibility when using Podman instead of Docker. |
| 6 | +# This allows azd and other tools expecting 'docker' command to work with Podman. |
| 7 | +# ============================================================================ |
| 8 | + |
| 9 | +set -euo pipefail |
| 10 | + |
| 11 | +info() { echo "ℹ️ $*"; } |
| 12 | +success() { echo "✅ $*"; } |
| 13 | +warn() { echo "⚠️ $*"; } |
| 14 | +fail() { echo "❌ $*" >&2; } |
| 15 | + |
| 16 | +# Check if Podman is installed |
| 17 | +if ! command -v podman &>/dev/null; then |
| 18 | + fail "Podman is not installed. Please install it first:" |
| 19 | + fail " macOS: brew install podman" |
| 20 | + fail " Linux: See https://podman.io/getting-started/installation" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# Check if docker command already exists |
| 25 | +if command -v docker &>/dev/null; then |
| 26 | + docker_version=$(docker --version 2>/dev/null || echo "unknown") |
| 27 | + info "Docker command already available: $docker_version" |
| 28 | + |
| 29 | + # Check if it's actually podman |
| 30 | + if docker --version 2>&1 | grep -q "podman"; then |
| 31 | + success "Docker is aliased to Podman - compatibility already configured" |
| 32 | + exit 0 |
| 33 | + else |
| 34 | + info "Using native Docker installation" |
| 35 | + exit 0 |
| 36 | + fi |
| 37 | +fi |
| 38 | + |
| 39 | +info "Setting up Podman Docker compatibility..." |
| 40 | + |
| 41 | +# Get Podman socket path |
| 42 | +PODMAN_SOCKET=$(podman info --format '{{.Host.RemoteSocket.Path}}' 2>/dev/null || echo "") |
| 43 | + |
| 44 | +if [[ -z "$PODMAN_SOCKET" ]]; then |
| 45 | + warn "Could not determine Podman socket path" |
| 46 | + warn "You may need to start a Podman machine:" |
| 47 | + warn " podman machine init" |
| 48 | + warn " podman machine start" |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +# Create docker symlink (requires sudo on most systems) |
| 53 | +INSTALL_DIR="/usr/local/bin" |
| 54 | + |
| 55 | +if [[ -w "$INSTALL_DIR" ]]; then |
| 56 | + ln -sf "$(command -v podman)" "$INSTALL_DIR/docker" |
| 57 | + success "Created docker symlink at $INSTALL_DIR/docker" |
| 58 | +else |
| 59 | + info "Creating docker symlink (may require password)..." |
| 60 | + sudo ln -sf "$(command -v podman)" "$INSTALL_DIR/docker" |
| 61 | + success "Created docker symlink at $INSTALL_DIR/docker" |
| 62 | +fi |
| 63 | + |
| 64 | +# Set up environment variables |
| 65 | +cat << 'EOF' |
| 66 | +
|
| 67 | +╭───────────────────────────────────────────────────────────── |
| 68 | +│ ✅ Podman Docker Compatibility Configured |
| 69 | +├───────────────────────────────────────────────────────────── |
| 70 | +│ |
| 71 | +│ Add these to your shell profile (~/.zshrc, ~/.bashrc): |
| 72 | +│ |
| 73 | +│ export DOCKER_HOST="unix:///run/podman/podman.sock" |
| 74 | +│ alias docker=podman |
| 75 | +│ |
| 76 | +│ Or run this command: |
| 77 | +│ echo 'export DOCKER_HOST="unix:///run/podman/podman.sock"' >> ~/.zshrc |
| 78 | +│ echo 'alias docker=podman' >> ~/.zshrc |
| 79 | +│ source ~/.zshrc |
| 80 | +│ |
| 81 | +╰───────────────────────────────────────────────────────────── |
| 82 | +EOF |
| 83 | + |
| 84 | +# Verify setup |
| 85 | +if command -v docker &>/dev/null; then |
| 86 | + docker_version=$(docker --version 2>/dev/null) |
| 87 | + success "Docker command verified: $docker_version" |
| 88 | +else |
| 89 | + fail "Docker symlink creation failed" |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | + |
| 93 | +info "Note: You may need to restart your terminal for changes to take effect" |
0 commit comments