[GH-ISSUE #1292] how to set up an fpm docker container with nginx container #739

Closed
opened 2026-02-26 02:34:08 +03:00 by kerem · 0 comments
Owner

Originally created by @cyh-ustc on GitHub (Mar 12, 2021).
Original GitHub issue: https://github.com/koel/koel/issues/1292

i tried to use an fpm docker with an nginx container cause i don't want many nginx instances.

and the web page works and i could upload songs.

while the music can't be played

sth wrong on xsendfile(transfer 310 B (0 B size))
that repeats thounds of times

{
	"Response Headers (310 B)": {
		"headers": [
			{
				"name": "Connection",
				"value": "keep-alive"
			},
			{
				"name": "Content-Disposition",
				"value": "inline; filename=\a.mp3\""
			},
			{
				"name": "Content-Type",
				"value": "audio/mp3"
			},
			{
				"name": "Date",
				"value": "Fri, 12 Mar 2021 15:46:11 GMT"
			},
			{
				"name": "Server",
				"value": "nginx/1.19.6"
			},
			{
				"name": "Transfer-Encoding",
				"value": "chunked"
			},
			{
				"name": "X-Powered-By",
				"value": "PHP/8.0.3"
			},
			{
				"name": "X-Sendfile",
				"value": "/music/__KOEL_UPLOADS__/a.mp3"
			}
		]
	}
}
docker run -d  --name koel \
    -v `pwd`/koel/html:/var/www/html \
    -v `pwd`/koel/music:/music \
    --link mysql:mysql \
    koel:fpm

docker run --name nginx \
	   --restart=always \
	   -p 443:443 \
	   -p 80:80 \
	   --link koel \
	   -v `pwd`/koel/html:/var/www/html \
	   -v `pwd`/koel/music:/var/www/html/public/music \
	   -v `pwd`/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
	   -v `pwd`/nginx/conf/sites-enabled:/etc/nginx/sites-enabled \
	   -v `pwd`/nginx/www:/var/www \
	   -v /etc/apt:/etc/apt \
	   -d nginx

nginx conf

server {
  listen          *:80;
  server_name     koel.xxx.yyy.zzz;
  root            /var/www/html/public;
  index           index.php;

  gzip            on;
  gzip_types      text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json;
  gzip_comp_level  9;
  client_max_body_size 512M;
  location /media/ {
    internal;

    alias       $upstream_http_x_media_root;

    access_log /var/log/nginx/koel.access.log;
    error_log  /var/log/nginx/koel.error.log;
  }


  location / {
    try_files   $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    try_files $uri $uri/ /index.php?$args;

    fastcgi_param     PATH_INFO $fastcgi_path_info;
    fastcgi_param     PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param     SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_pass              koel:9000;
    fastcgi_index             index.php;
    fastcgi_split_path_info   ^(.+\.php)(/.+)$;
    fastcgi_intercept_errors  on;
    include                   fastcgi_params;
  }
}


dockerfile

# Download koel's released archive
FROM alpine:3.13.2 as release-downloader

# The koel version to download
ARG KOEL_VERSION_REF=v5.0.2

# Install curl to download the release tar.gz
RUN apk add --no-cache curl

# Download the koel release matching the version and remove anything not necessary for production
RUN curl -L https://github.com/koel/koel/releases/download/${KOEL_VERSION_REF}/koel-${KOEL_VERSION_REF}.tar.gz | tar -xz -C /tmp \
  && cd /tmp/koel/ \
  && rm -rf .editorconfig \
    .eslintignore \
    .eslintrc \
    .git \
    .gitattributes \
    .github \
    .gitignore \
    .gitmodules \
    .gitpod.dockerfile \
    .gitpod.yml \
    composer.lock \
    cypress \
    cypress.json \
    nginx.conf.example \
    package.json \
    phpstan.neon.dist \
    phpunit.xml.dist \
    resources/artifacts/ \
    resources/assets/ \
    ruleset.xml \
    tag.sh \
    tests \
    webpack.config.js \
    webpack.mix.js \
    yarn.lock

# The runtime image.
FROM php:fpm

# Install koel runtime dependencies.
RUN apt-get update && \
  apt-get install --yes --no-install-recommends \
    rsync \
    libapache2-mod-xsendfile \
    libzip-dev \
    zip \
    ffmpeg \
    libpng-dev \
    libjpeg62-turbo-dev \
  && docker-php-ext-configure gd --with-jpeg \
  # https://laravel.com/docs/8.x/deployment#server-requirements
  # ctype, fileinfo, json, mbstring, openssl, PDO, tokenizer and xml are already activated in the base image
  && docker-php-ext-install \
    bcmath \
    exif \
    gd \
    pdo_mysql \
    zip \
  && apt-get clean \
  # Create the music volume so it has the correct permissions
  && mkdir /music \
  && chown www-data:www-data /music

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

# Copy the downloaded release
COPY --from=release-downloader --chown=www-data:www-data /tmp/koel /tmp/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", "/var/www/html"]

ENV FFMPEG_PATH=/usr/bin/ffmpeg \
    MEDIA_PATH=/music \
    STREAMING_METHOD=x-sendfile

# Setup bootstrap script.
COPY koel-entrypoint /usr/local/bin/
ENTRYPOINT ["koel-entrypoint"]
CMD ["php-fpm"]

entrypoint

#!/bin/bash

set -e

rsync -av --exclude 'public/img/covers/*' /tmp/html/ /var/www/html
# Change to program root directory.
cd /var/www/html

# Fix permissions for the cache directory because running php artisan koel:sync can set them to root
mkdir -p storage/framework/cache/data/
chown www-data:www-data storage/framework/cache/data/

if [[ -n "$APP_KEY" ]] || [[ -s .env ]] ; then
    echo "APP_KEY exists. Skipping key generation"
else
    echo "generating app key"
    echo 'APP_KEY=' >> .env
    chown www-data:www-data .env
    php artisan key:generate
fi

# Run the next entrypoint in the chain.
echo "running docker-php-entrypoint with arguments $@"
docker-php-entrypoint $@
Originally created by @cyh-ustc on GitHub (Mar 12, 2021). Original GitHub issue: https://github.com/koel/koel/issues/1292 i tried to use an fpm docker with an nginx container cause i don't want many nginx instances. and the web page works and i could upload songs. while the music can't be played sth wrong on xsendfile(transfer 310 B (0 B size)) that repeats thounds of times ``` { "Response Headers (310 B)": { "headers": [ { "name": "Connection", "value": "keep-alive" }, { "name": "Content-Disposition", "value": "inline; filename=\a.mp3\"" }, { "name": "Content-Type", "value": "audio/mp3" }, { "name": "Date", "value": "Fri, 12 Mar 2021 15:46:11 GMT" }, { "name": "Server", "value": "nginx/1.19.6" }, { "name": "Transfer-Encoding", "value": "chunked" }, { "name": "X-Powered-By", "value": "PHP/8.0.3" }, { "name": "X-Sendfile", "value": "/music/__KOEL_UPLOADS__/a.mp3" } ] } } ``` ``` docker run -d --name koel \ -v `pwd`/koel/html:/var/www/html \ -v `pwd`/koel/music:/music \ --link mysql:mysql \ koel:fpm docker run --name nginx \ --restart=always \ -p 443:443 \ -p 80:80 \ --link koel \ -v `pwd`/koel/html:/var/www/html \ -v `pwd`/koel/music:/var/www/html/public/music \ -v `pwd`/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \ -v `pwd`/nginx/conf/sites-enabled:/etc/nginx/sites-enabled \ -v `pwd`/nginx/www:/var/www \ -v /etc/apt:/etc/apt \ -d nginx ``` nginx conf ``` server { listen *:80; server_name koel.xxx.yyy.zzz; root /var/www/html/public; index index.php; gzip on; gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json; gzip_comp_level 9; client_max_body_size 512M; location /media/ { internal; alias $upstream_http_x_media_root; access_log /var/log/nginx/koel.access.log; error_log /var/log/nginx/koel.error.log; } location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { try_files $uri $uri/ /index.php?$args; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass koel:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_intercept_errors on; include fastcgi_params; } } ``` dockerfile ``` # Download koel's released archive FROM alpine:3.13.2 as release-downloader # The koel version to download ARG KOEL_VERSION_REF=v5.0.2 # Install curl to download the release tar.gz RUN apk add --no-cache curl # Download the koel release matching the version and remove anything not necessary for production RUN curl -L https://github.com/koel/koel/releases/download/${KOEL_VERSION_REF}/koel-${KOEL_VERSION_REF}.tar.gz | tar -xz -C /tmp \ && cd /tmp/koel/ \ && rm -rf .editorconfig \ .eslintignore \ .eslintrc \ .git \ .gitattributes \ .github \ .gitignore \ .gitmodules \ .gitpod.dockerfile \ .gitpod.yml \ composer.lock \ cypress \ cypress.json \ nginx.conf.example \ package.json \ phpstan.neon.dist \ phpunit.xml.dist \ resources/artifacts/ \ resources/assets/ \ ruleset.xml \ tag.sh \ tests \ webpack.config.js \ webpack.mix.js \ yarn.lock # The runtime image. FROM php:fpm # Install koel runtime dependencies. RUN apt-get update && \ apt-get install --yes --no-install-recommends \ rsync \ libapache2-mod-xsendfile \ libzip-dev \ zip \ ffmpeg \ libpng-dev \ libjpeg62-turbo-dev \ && docker-php-ext-configure gd --with-jpeg \ # https://laravel.com/docs/8.x/deployment#server-requirements # ctype, fileinfo, json, mbstring, openssl, PDO, tokenizer and xml are already activated in the base image && docker-php-ext-install \ bcmath \ exif \ gd \ pdo_mysql \ zip \ && apt-get clean \ # Create the music volume so it has the correct permissions && mkdir /music \ && chown www-data:www-data /music # Copy php.ini COPY ./php.ini "$PHP_INI_DIR/php.ini" # /usr/local/etc/php/php.ini # Copy the downloaded release COPY --from=release-downloader --chown=www-data:www-data /tmp/koel /tmp/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", "/var/www/html"] ENV FFMPEG_PATH=/usr/bin/ffmpeg \ MEDIA_PATH=/music \ STREAMING_METHOD=x-sendfile # Setup bootstrap script. COPY koel-entrypoint /usr/local/bin/ ENTRYPOINT ["koel-entrypoint"] CMD ["php-fpm"] ``` entrypoint ``` #!/bin/bash set -e rsync -av --exclude 'public/img/covers/*' /tmp/html/ /var/www/html # Change to program root directory. cd /var/www/html # Fix permissions for the cache directory because running php artisan koel:sync can set them to root mkdir -p storage/framework/cache/data/ chown www-data:www-data storage/framework/cache/data/ if [[ -n "$APP_KEY" ]] || [[ -s .env ]] ; then echo "APP_KEY exists. Skipping key generation" else echo "generating app key" echo 'APP_KEY=' >> .env chown www-data:www-data .env php artisan key:generate fi # Run the next entrypoint in the chain. echo "running docker-php-entrypoint with arguments $@" docker-php-entrypoint $@ ```
kerem closed this issue 2026-02-26 02:34:08 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/koel-koel#739
No description provided.