Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*

# Allow specific files
!/apache.conf
!/apache/*
!/php.ini
!/koel-entrypoint
!/koel-init
169 changes: 104 additions & 65 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,98 @@
# The runtime image.
FROM php:8.4.8-apache-bookworm
FROM alpine:3.23.2

# The koel version to download
ARG KOEL_VERSION_REF=v8.3.0

# Download the koel release matching the version and remove anything not necessary for production
# Install dependencies
RUN apk add --no-cache --no-interactive \
curl \
apache2 \
apache2-proxy \
# php-fpm because it's so much faster and efficient in handling web requests, php for cli commands. need to find a way to maybe not have both bloating the image
php \
php-fpm \
libzip-dev \
zip \
ffmpeg \
libpng-dev \
libjpeg-turbo-dev \
libpq-dev \
libwebp-dev \
libavif-dev \
# https://laravel.com/docs/8.x/deployment#server-requirements
php84-ctype \
php84-fileinfo \
php84-json \
php84-mbstring \
php84-openssl \
php84-tokenizer \
php84-xml \
php84-dom \
php84-bcmath \
php84-exif \
php84-gd \
php84-pdo \
php84-pdo_mysql \
php84-pdo_pgsql \
php84-pgsql \
php84-zip \
php84-session \
busybox-suid \
musl-locales \
musl-locales-lang \
tzdata \
# as well as nano for easier debugging and updating configs
nano \
# Set locale to prevent removal of non-ASCII path characters when transcoding with ffmpeg. do this first so all the php configurations make use of this as well
# See https://github.com/koel/docker/pull/91 & https://krython.com/post/resolving-alpine-linux-locale-issues/
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& export LANG=en_US.UTF-8 \
&& export LC_ALL=en_US.UTF-8 \
&& echo 'export LANG=en_US.UTF-8' >> /etc/profile \
&& echo 'export LC_ALL=en_US.UTF-8' >> /etc/profile

# Install x-sendfile for apache2, fix home folder
RUN apk add --no-cache apache2-dev gcc musl-dev \
&& curl -o mod_xsendfile.c https://tn123.org/mod_xsendfile/mod_xsendfile.c \
&& apxs -cia mod_xsendfile.c \
&& rm mod_xsendfile.* \
&& apk del --no-cache apache2-dev gcc musl-dev \
&& mkdir /var/www/lib \
&& ln -s /usr/lib/apache2 /var/www/lib/apache2

# Copy Apache configuration
COPY apache/site.conf /etc/apache2/conf.d/
COPY apache/httpd.conf /etc/apache2/
COPY apache/www.conf /etc/php84/php-fpm.d/

# Copy php.ini
COPY ./php.ini "$PHP_INI_DIR/php.ini"

# make crontab file
RUN touch /etc/crontabs/www-data


# Setup user and folders
RUN adduser -S www-data -G www-data -h /var/www/ -H
RUN mkdir -p /var/www/html && chown www-data:www-data /var/www/html && chown www-data /var/log/php84 && mkdir /var/log/apache && chown www-data /var/log/apache

# setup volume folders
RUN mkdir /music \
&& chown www-data:www-data /music \
# Create the search-indexes volume so it has the correct permissions
&& mkdir -p /var/www/html/storage/search-indexes \
&& chown -R www-data:www-data /var/www/html

# Volumes for the music files and search index
# This declaration must be AFTER creating the folders and setting their permissions
# and AFTER changing to non-root user.
# Otherwise, they are owned by root and the user cannot write to them.
VOLUME ["/music", "/var/www/html/storage/search-indexes"]

# Do the actual application setup as www-data user

# Download the koel release matching the version and remove anything not necessary for production, then move it to the right place. All in one command so we don't duplicate data across layers
RUN curl -L https://github.com/koel/koel/releases/download/${KOEL_VERSION_REF}/koel-${KOEL_VERSION_REF}.tar.gz | tar -xz -C /tmp \
&& chown www-data:www-data /tmp/koel \
&& chmod 755 /tmp/koel \
Expand Down Expand Up @@ -43,87 +131,38 @@ RUN curl -L https://github.com/koel/koel/releases/download/${KOEL_VERSION_REF}/k
eslint.config.js \
postcss.config.cjs \
commitlint.config.js \
.htaccess.example

# Install koel runtime dependencies.
RUN apt-get update \
&& apt-get install --yes --no-install-recommends \
cron \
libapache2-mod-xsendfile \
libzip-dev \
zip \
ffmpeg \
locales \
libpng-dev \
libjpeg62-turbo-dev \
libpq-dev \
libwebp-dev \
libavif-dev \
# to have a simple editor
nano \
&& docker-php-ext-configure gd --with-jpeg --with-webp --with-avif \
# https://laravel.com/docs/8.x/deployment#server-requirements
# ctype, fileinfo, json, mbstring, openssl, tokenizer and xml are already activated in the base image
&& docker-php-ext-install \
bcmath \
exif \
gd \
pdo \
pdo_mysql \
pdo_pgsql \
pgsql \
zip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
# Create the music volume so it has the correct permissions
&& mkdir /music \
&& chown www-data:www-data /music \
# Create the search-indexes volume so it has the correct permissions
&& mkdir -p /var/www/html/storage/search-indexes \
&& chown www-data:www-data /var/www/html/storage/search-indexes \
# Set locale to prevent removal of non-ASCII path characters when transcoding with ffmpeg
# See https://github.com/koel/docker/pull/91
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& /usr/sbin/locale-gen

# Copy Apache configuration
COPY ./apache.conf /etc/apache2/sites-available/000-default.conf

# Copy php.ini
COPY ./php.ini "$PHP_INI_DIR/php.ini"
# /usr/local/etc/php/php.ini

# Deploy Apache configuration
RUN a2enmod rewrite

# Copy the downloaded release
RUN cp -R /tmp/koel/. /var/www/html \
.htaccess.example \
CLAUDE.md \
&& cp -R /tmp/koel/. /var/www/html \
&& chown -R www-data:www-data /var/www/html \
&& mv /var/www/html/public/manifest.json.example /var/www/html/public/manifest.json \
&& chown -R www-data:www-data /var/www/html

# Volumes for the music files and search index
# This declaration must be AFTER creating the folders and setting their permissions
# and AFTER changing to non-root user.
# Otherwise, they are owned by root and the user cannot write to them.
VOLUME ["/music", "/var/www/html/storage/search-indexes"]
# we use php-pfm because it's plain better, but that means htaccess php directives can't be parsed here
&& sed -e '/^php*/ s/^#*/#/' -i /var/www/html/public/.htaccess \
&& rm -R /tmp/koel

USER www-data

# Apply lalvel optimalizations
RUN cd /var/www/html \
&& php artisan route:cache \
&& php artisan event:cache \
&& php artisan view:cache


ENV FFMPEG_PATH=/usr/bin/ffmpeg \
MEDIA_PATH=/music \
STREAMING_METHOD=x-sendfile \
LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8

USER root
# Setup bootstrap script.
COPY koel-entrypoint /usr/local/bin/
COPY koel-init /usr/local/bin/
WORKDIR /var/www/html
ENTRYPOINT ["koel-entrypoint"]
CMD ["apache2-foreground"]
CMD [""]

EXPOSE 80

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ For instance, during the first run, this command will generate the `APP_KEY`, cr
In order to run this command, you first need to `exec` into the container (replace `<container_name_for_koel>` with the name of your running Koel container):

```bash
docker exec --user www-data -it <container_name_for_koel> bash
docker exec --user www-data -it <container_name_for_koel> sh
```

Once inside the container, run the `koel:init` command:
Expand Down
Loading