Files
laravel-shopping-cart/Claude.Dockerfile
T
2026-04-09 16:35:08 -06:00

156 lines
4.8 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
FROM alpine:latest
# ---------------------------------------------------------------------------
# 1. SYSTEM PACKAGES
# - curl is required for the native Claude Code bash installer
# - nodejs / npm / pnpm are NO LONGER needed for Claude Code itself,
# but keep them if your project (e.g. Laravel front-end) needs them.
# Remove those three lines if you don't need Node in the container.
# - libgcc / libstdc++ / ripgrep are required by the native binary on
# Alpine (musl-based). Without these the installer will fail.
# ---------------------------------------------------------------------------
RUN apk add --no-cache \
bash \
ca-certificates \
curl \
tar \
xz \
libgcc \
libstdc++ \
ripgrep \
mariadb-client \
openssh-client \
openssh-client-default \
openssl \
php84 \
php84-bcmath \
php84-bz2 \
php84-curl \
php84-dom \
php84-exif \
php84-fileinfo \
php84-gd \
php84-gettext \
php84-gmp \
php84-iconv \
php84-imap \
php84-intl \
php84-mbstring \
php84-mysqlnd \
php84-pdo \
php84-pdo_mysql \
php84-pdo_pgsql \
php84-pdo_sqlite \
php84-pecl-apcu \
php84-pecl-igbinary \
php84-pecl-grpc \
php84-pecl-lzf \
php84-pecl-maxminddb \
php84-pecl-msgpack \
php84-pecl-redis \
php84-pgsql \
php84-phar \
php84-posix \
php84-session \
php84-simplexml \
php84-soap \
php84-sockets \
php84-sodium \
php84-sqlite3 \
php84-tokenizer \
php84-xml \
php84-xmlreader \
php84-xmlwriter \
php84-zip \
sqlite
# ---------------------------------------------------------------------------
# 2. INSTALL COMPOSER (essential for PHP)
# ---------------------------------------------------------------------------
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/local/bin --filename=composer
# ---------------------------------------------------------------------------
# 3. NON-ROOT USER
# Create a user whose UID/GID matches your host user so that any files
# written inside the container are owned by YOU on the host, not root.
#
# HOW TO USE:
# Pass --build-arg HOST_UID=$(id -u) --build-arg HOST_GID=$(id -g)
# when you run `docker build`, or hard-code the values below.
#
# Example build command:
# docker build \
# --build-arg HOST_UID=$(id -u) \
# --build-arg HOST_GID=$(id -g) \
# -t my-claude-image .
#
# Example run command (mount your project into /app):
# docker run --rm -it \
# -v "$(pwd)":/app \
# -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
# my-claude-image
# ---------------------------------------------------------------------------
ARG HOST_UID=1000
ARG HOST_GID=1000
RUN addgroup -g "${HOST_GID}" brian \
&& adduser -D -u "${HOST_UID}" -G brian -s /bin/bash brian
# ---------------------------------------------------------------------------
# 4. INSTALL CLAUDE CODE (native bash installer Anthropic recommended)
# The native binary:
# • Requires NO Node.js
# • Auto-updates in the background
# • Installs to ~/.local/bin (per-user, no sudo required)
#
# On Alpine the installer needs USE_BUILTIN_RIPGREP=0 because the
# bundled ripgrep binary is glibc-linked; we installed ripgrep via apk
# above instead.
#
# We switch to the brian for the install so the binary lands in
# /home/brian/.local/bin (not /root/.local/bin).
# ---------------------------------------------------------------------------
USER brian
ENV HOME=/home/brian
ENV USE_BUILTIN_RIPGREP=0
RUN curl -fsSL https://claude.ai/install.sh | bash
# Make sure the installed binary is on PATH for subsequent RUN steps and
# at container runtime.
ENV PATH="/home/brian/.local/bin:${PATH}"
# ---------------------------------------------------------------------------
# 5. APP DIRECTORIES
# Create persistent-data dirs as the non-root user so Claude Code can
# read/write its config without permission errors.
# ---------------------------------------------------------------------------
RUN mkdir -p /home/brian/.config/claude-code \
&& mkdir -p /home/brian/.ssh \
&& mkdir -p /home/brian/app
# ---------------------------------------------------------------------------
# 5.1 DIRECTORY PERMISSIONS
# Adjust permissions on some directories as needed.
# ---------------------------------------------------------------------------
RUN chmod 700 /home/brian/.ssh
# ---------------------------------------------------------------------------
# 6. WORKDIR & SHELL
# ---------------------------------------------------------------------------
WORKDIR /home/brian/app
SHELL ["/bin/bash", "-c"]
# ---------------------------------------------------------------------------
# 7. DEFAULT COMMAND
# ---------------------------------------------------------------------------
CMD ["claude"]