Add dockerfile-for-webserver-with-php/ubuntu-lighttpd-php.dockerfile

dockerfile for webserver container. feel free to edit as needed.
This commit is contained in:
Nathaniel Smith 2025-02-18 05:06:19 +00:00
parent 5406c6ec74
commit eaa515d839

View File

@ -0,0 +1,57 @@
# Use the official Ubuntu 18.04 base image
FROM ubuntu:18.04
# Set the maintainer label
LABEL maintainer="Nathaniel Smith"
# Set non-interactive mode for apt-get
ENV DEBIAN_FRONTEND=noninteractive
# Optimize apt-get and prevent services from starting during installation
RUN set -xe && \
echo '#!/bin/sh' > /usr/sbin/policy-rc.d && \
echo 'exit 101' >> /usr/sbin/policy-rc.d && \
chmod +x /usr/sbin/policy-rc.d && \
dpkg-divert --local --rename --add /sbin/initctl && \
cp -a /usr/sbin/policy-rc.d /sbin/initctl && \
sed -i 's/^exit.*/exit 0/' /sbin/initctl && \
echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup && \
echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean && \
echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean && \
echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean && \
echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages && \
echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes && \
echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests
# Create necessary directories and mark the container as a Docker container
RUN mkdir -p /run/systemd && echo 'docker' > /run/systemd/container
# Set the default command to bash (for interactive sessions)
CMD ["/bin/bash"]
# Update package list, install packages, and configure Lighttpd with PHP
RUN apt-get update && \
apt-get upgrade -y && \
echo 5 | apt-get install -y tzdata && \
apt-get install -y php-fpm php-mbstring php-xml php-mysql apt-transport-https libterm-readline-gnu-perl lighttpd && \
apt-get autoremove && apt-get clean && \
lighttpd-enable-mod fastcgi && lighttpd-enable-mod fastcgi-php && \
mkdir -p /run/php /var/run/lighttpd && \
touch /run/php/php7.2-fpm.sock && \
sed -i 's/.*;cgi.fix_pathinfo=1.*/cgi.fix_pathinfo=1/' /etc/php/7.2/fpm/php.ini && \
ln -s /var/run/php/php7.2-fpm.sock /var/run/lighttpd/php.socket-0
# Change ownership of the Lighttpd log directory
RUN chown -R www-data:www-data /var/log/lighttpd
# Modify the Lighttpd configuration file to change the document root
RUN sed -i 's|server.document-root.*|server.document-root = "/var/www/html"|' /etc/lighttpd/lighttpd.conf
# Expose port 80 for the web server
EXPOSE 80
# Define a volume for the web root
VOLUME /var/www/html
# Start PHP-FPM and Lighttpd when the container runs
CMD ["/bin/sh", "-c", "php-fpm7.2 -D && /usr/sbin/lighttpd -D -f /etc/lighttpd/lighttpd.conf && bash"]