Using private Composer packages in Docker
Published: 10/4/2024
-
Create a new fine-grained GitHub PAT with read-only access to Contents on repositories you want Composer to access.
-
Add GitHub PAT as JSON to your environment variables
# Replace `github_pat_xxx` with your token
COMPOSER_AUTH_JSON='{ "github-oauth": { "github.com": "github_pat_XXXX" } }'
- Update
docker-compose.yaml
andDockerfile
# docker-compose.yaml
services:
php:
build:
secrets:
- COMPOSER_AUTH_JSON
secrets:
COMPOSER_AUTH_JSON:
environment: COMPOSER_AUTH_JSON
# Dockerfile
RUN --mount=type=secret,id=composer_auth_json,dst=/app/auth.json \
composer install --no-autoloader --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-scripts
[!IMPORTANT]
Using Coolify? Check out this article on how to use build secrets in Coolify.