Open
Description
For those who are curious, and want to use this excellent Docker image....
- Change the php-base version of Alpine
- Change the Roadrunner version (this dies with permission errors otherwise)
- Change the Laravel version variable
FROM php:8.1.12-cli-alpine3.16 as php-base
WORKDIR /srv/laravel
RUN apk add --no-cache $PHPIZE_DEPS autoconf libzip-dev zip unzip wget curl && \
docker-php-ext-install bcmath ctype pcntl sockets zip && \
rm -rf /var/www && \
chown -R www-data:www-data /srv/laravel
# This stage is so that we can build up everything that doesn't require Laravel
# so as to not bust the caching for those items.
FROM php-base as octane-base
COPY --from=spiralscout/roadrunner:latest /usr/bin/rr /usr/bin/rr
# This really shouldn't be modified, so we aren't advertising the env variable.
# It allows us to globally install chokidar without modifying the Laravel package.json.
ENV NODE_PATH "/home/www-data/.npm-global/lib/node_modules"
RUN apk add --no-cache nodejs npm && \
mkdir "/home/www-data/.npm-global/" && \
npm config set prefix "/home/www-data/.npm-global/" && \
npm install -g chokidar
# Here we have a build container so that it is not necessary to pull composer into
# the final container. We are going to create a new Laravel project and install Octane.
FROM php-base as laravel
ARG LARAVEL_VERSION="9.*"
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN cd /srv && \
composer create-project laravel/laravel="${LARAVEL_VERSION}" laravel && \
cd /srv/laravel && \
composer require laravel/octane spiral/roadrunner && \
php artisan octane:install --server="roadrunner" && \
rm "/srv/laravel/.env"
# This is our final container. We will install the RoadRunner binary and copy over
# our built version of Laravel.
FROM octane-base
USER www-data
COPY --from=laravel --chown=www-data:www-data /srv/laravel/ /srv/laravel/
# Allow the user to specify RoadRunner options via ENV variables.
ENV ROADRUNNER_MAX_REQUESTS "500"
ENV ROADRUNNER_WATCH $false
ENV ROADRUNNER_WORKERS "auto"
# Expose the ports that Octane is using.
EXPOSE 8000
# Run RoadRunner
CMD if [[ -z $ROADRUNNER_WATCH ]] ; then \
php artisan octane:start --server="roadrunner" --host="0.0.0.0" --workers=${ROADRUNNER_WORKERS} --max-requests=${ROADRUNNER_MAX_REQUESTS} ; \
else \
php artisan octane:start --server="roadrunner" --host="0.0.0.0" --workers=${ROADRUNNER_WORKERS} --max-requests=${ROADRUNNER_MAX_REQUESTS} --watch ; \
fi
# Check the health status using the Octane status command.
HEALTHCHECK CMD php artisan octane:status --server="roadrunner"
For a list of PHP extensions you can install in Alpine: https://gist.github.com/chronon/95911d21928cff786e306c23e7d1d3f3 .
If you need to add others (e.g. curl, mbstring), you will need the development files. Find them here: https://pkgs.alpinelinux.org/packages
RUN apk add --no-cache libzip-dev curl-dev libxml2 libxml2-dev oniguruma-dev icu-dev freetype libpng libjpeg-turbo freetype-dev libpng-dev libjpeg-turbo-dev && \
For MongoDB and Redis you will need to install from PECL, which requires autoconf
and $PHPIZE_DEPS
:
RUN pecl install mongodb && docker-php-ext-enable mongodb
RUN pecl install redis && docker-php-ext-enable redis
Another issue here is the directory binding. The latest version of Docker wants volumes.
Example Compose setup:
myfolder/
docker/
laravel.Dockerfile
laravel-src/
app/
config/
laravel:
build:
context: ./docker/
dockerfile: laravel.Dockerfile
restart: unless-stopped
ports:
- '127.0.0.1:8000:8000' # run on port 8000 localhost only, port 8000 on the container
environment:
ROADRUNNER_MAX_REQUESTS: 250
ROADRUNNER_WATCH: "yes"
ROADRUNNER_WORKERS: 6
APP_NAME: "Example"
APP_ENV: "local"
volumes:
- ./laravel-src:/srv/laravel
Metadata
Metadata
Assignees
Labels
No labels