Skip to content

🐳 Docker deployment

Composer Skills ships a Dockerfile and docker-compose.yml for easy containerization of the CLI tool or SDK-based programs. This page explains how to use the project's built-in Docker files and offers multi-stage build recommendations.

📦 Project's built-in Dockerfile

The Dockerfile in the project root uses multi-stage builds to separate build and runtime environments:

dockerfile
# ---- Build stage ----
FROM golang:1.20-alpine AS build
WORKDIR /app
COPY go.mod go.sum* ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -o /composer-skills cmd/main.go

# ---- Runtime stage ----
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=build /composer-skills .
RUN mkdir -p /data
ENV OUTPUT_DIR=/data
ENTRYPOINT ["./composer-skills"]
CMD ["--help"]

Key points:

  • 🐹 Build stage uses golang:1.20-alpine, compiles a static binary (CGO_ENABLED=0).
  • 🪶 Runtime stage uses alpine, only installs ca-certificates for HTTPS support; the image stays tiny.
  • 📁 /data directory is for mounting output; environment variable OUTPUT_DIR=/data.

Go version alignment

The project's go.mod declares go 1.23.0. If you get a version error using the built-in Dockerfile, bump the base image to golang:1.23-alpine. We recommend using the "Recommended Dockerfile" below.

🚀 Running with Docker

Build the image:

bash
docker build -t composer-skills .

Run a few common commands (results mounted to ./data):

bash
mkdir -p data

# Statistics
docker run -v "$(pwd)/data:/data" composer-skills \
    -stats -output /data/statistics.json

# Specific package details
docker run -v "$(pwd)/data:/data" composer-skills \
    -package symfony/console -output /data/symfony-console.json

# Security advisories
docker run -v "$(pwd)/data:/data" composer-skills \
    -advisories -output /data/advisories.json

Pure Go, no PHP needed

These commands use the Packagist API (-stats/-package/-advisories), so the container doesn't need PHP installed. That keeps the image tiny. You only need PHP when running local composer install/audit.

🐙 Running with Docker Compose

The docker-compose.yml in the project root defines multiple services; each command runs one task:

yaml
version: '3'
services:
  composer-skills:        # Get statistics
    build: .
    volumes: [./data:/data]
    command: ["-stats"]
  get-package:            # Get specific package info
    build: .
    volumes: [./data:/data]
    command: ["-package", "symfony/console", "-output", "/data/symfony-console.json"]
  get-advisories:         # Get security advisories
    build: .
    volumes: [./data:/data]
    command: ["-advisories", "-output", "/data/advisories.json"]
  popular-packages:       # Run popular packages example
    build: .
    volumes: [./data:/data]
    entrypoint: ["/bin/sh", "-c"]
    command: |
      cd /app && go build -o /root/popular-packages examples/popular_packages/main.go &&
      cd /root && ./popular-packages
  security-monitor:       # Run security monitor example
    build: .
    volumes: [./data:/data]
    entrypoint: ["/bin/sh", "-c"]
    command: |
      cd /app && go build -o /root/security-monitor examples/security_monitor/main.go &&
      cd /root && ./security-monitor

Common operations:

bash
docker-compose up composer-skills     # Statistics
docker-compose up get-package         # Package details
docker-compose up get-advisories      # Security advisories
docker-compose up popular-packages    # Popular packages example
docker-compose up security-monitor    # Security monitor example

Results land in the ./data directory.

Permission issues

If ./data isn't writable, adjust permissions:

bash
chmod -R 777 ./data

📌 Custom runs

To run with different packages or parameters, override command:

bash
docker run -v "$(pwd)/data:/data" composer-skills \
    -package laravel/framework -output /data/laravel-framework.json

Or add a new service in docker-compose.yml.

If you're writing your own program based on the SDK, we recommend this Go-version-aligned multi-stage Dockerfile:

dockerfile
# ---- Build stage ----
FROM golang:1.23-alpine AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
# Compile your own program, static linking
RUN CGO_ENABLED=0 GOOS=linux go build -o /app ./ci/main.go

# ---- Runtime stage ----
FROM alpine:latest
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=build /app .
ENTRYPOINT ["./app"]

If the runtime stage needs local Composer CLI (running install/audit), use a PHP-enabled runtime image:

dockerfile
# ---- Runtime stage (needs PHP + Composer)----
FROM php:8.2-cli
RUN apt-get update && apt-get install -y --no-install-recommends \
    git unzip libzip-dev && docker-php-ext-install zip
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
COPY --from=build /app /usr/local/bin/app
WORKDIR /project
ENTRYPOINT ["app"]

Borrowing from the official Composer image

COPY --from=composer:2 /usr/bin/composer /usr/bin/composer copies the binary directly from the official Composer image, saving you a manual install. You could also let Composer Skills auto-install on container startup, but pre-installing is faster.

🧭 Next steps

Released under the MIT License