yt / Dockerfile
OrbitMC's picture
Update Dockerfile
1303c06 verified
Raw
History Blame Contribute Delete
4.35 kB
# syntax=docker/dockerfile:1.4
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
# Install all dependencies (Nginx, MariaDB, Redis, PHP 8.1, Supervisor)
RUN apt-get update && apt-get install -y \
curl wget unzip tar supervisor cron \
mariadb-server redis-server nginx \
php-cli php-fpm php-mysql php-mbstring \
php-bcmath php-xml php-curl php-zip php-gd \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/pterodactyl
# Download and extract Pterodactyl Panel
RUN curl -Lo panel.tar.gz https://github.com/pterodactyl/panel/releases/latest/download/panel.tar.gz \
&& tar -xzvf panel.tar.gz \
&& chmod -R 755 storage/* bootstrap/cache/ \
&& cp .env.example .env
# Start MariaDB temporarily to initialize the database and install the panel
RUN service mariadb start \
&& sleep 5 \
&& mysql -e "CREATE DATABASE panel;" \
&& mysql -e "CREATE USER 'pterodactyl'@'127.0.0.1' IDENTIFIED BY 'password';" \
&& mysql -e "GRANT ALL PRIVILEGES ON panel.* TO 'pterodactyl'@'127.0.0.1' WITH GRANT OPTION;" \
&& mysql -e "FLUSH PRIVILEGES;" \
&& composer install --no-dev --optimize-autoloader \
&& php artisan key:generate --force \
&& sed -i 's/DB_PASSWORD=/DB_PASSWORD=password/g' .env \
&& sed -i 's/APP_URL=http:\/\/localhost/APP_URL=http:\/\/localhost:7860/g' .env \
&& sed -i 's/CACHE_DRIVER=file/CACHE_DRIVER=redis/g' .env \
&& sed -i 's/SESSION_DRIVER=file/SESSION_DRIVER=redis/g' .env \
&& sed -i 's/QUEUE_CONNECTION=sync/QUEUE_CONNECTION=redis/g' .env \
&& php artisan migrate --seed --force \
&& php artisan p:user:make --email="admin@example.com" --username="admin" --name-first="Admin" --name-last="User" --password="admin" --admin=1 \
&& chown -R www-data:www-data /var/www/pterodactyl/*
# Configure Nginx to listen on Hugging Face's default port (7860)
# Using "EOF" prevents Docker from interpreting Nginx variables like $uri
RUN rm /etc/nginx/sites-enabled/default
COPY <<"EOF" /etc/nginx/sites-enabled/pterodactyl.conf
server {
listen 7860;
server_name _;
root /var/www/pterodactyl/public;
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/pterodactyl.app-error.log error;
client_max_body_size 100m;
client_body_timeout 120s;
sendfile off;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PHP_VALUE "upload_max_filesize = 100M \n post_max_size=100M";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTP_PROXY "";
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
EOF
# Configure Supervisord to run all required services in a single container
COPY <<"EOF" /etc/supervisor/conf.d/supervisord.conf
[supervisord]
nodaemon=true
user=root
[program:mysql]
command=/usr/bin/mysqld_safe
autostart=true
autorestart=true
[program:redis]
command=/usr/bin/redis-server
autostart=true
autorestart=true
[program:php-fpm]
command=/usr/sbin/php-fpm8.1 -F
autostart=true
autorestart=true
[program:nginx]
command=/usr/sbin/nginx -g "daemon off;"
autostart=true
autorestart=true
[program:pteroq]
command=php /var/www/pterodactyl/artisan queue:work --queue=high,standard,low --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
EOF
# Fix PHP-FPM socket directory permissions
RUN mkdir -p /run/php && chown -R www-data:www-data /run/php
# Expose the single port required by Hugging Face Spaces
EXPOSE 7860
# Start Supervisor which handles Nginx, MariaDB, PHP-FPM, Redis, and Pterodactyl Queue
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]