Files
ansible-lemp-wordpress/docker/Dockerfile
Sebastian Palencsar 1fa863f107 fix: replace mysql-server with mariadb-server for Debian 12/13 compatibility
- Use mariadb-server instead of mysql-server (works on both Ubuntu and Debian)
- Update mysql_service to mariadb for proper service management
- Update docker/Dockerfile and start-services.sh for MariaDB
2026-05-06 12:59:15 +02:00

117 lines
3.0 KiB
Docker
Executable File

# Optimized multi-stage Dockerfile for LEMP WordPress testing
# This Dockerfile creates a lightweight, secure testing environment
# Stage 1: Base system with essential packages
FROM ubuntu:24.04 AS base
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe/Berlin
# Create necessary directories and users early
RUN mkdir -p /var/run/sshd /var/log/supervisor \
&& groupadd -r ansible && useradd -r -g ansible ansible \
&& echo 'ansible ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Install base system packages in a single layer
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
# Core system
ca-certificates \
gnupg \
lsb-release \
apt-transport-https \
# SSH and system control
openssh-server \
sudo \
systemd \
systemd-sysv \
# Python for Ansible
python3 \
python3-pip \
python3-venv \
python3-dev \
# Essential utilities
curl \
wget \
unzip \
git \
vim \
nano \
htop \
net-tools \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Stage 2: Runtime with LEMP stack
FROM base AS runtime
# Install LEMP stack packages
RUN apt-get update && apt-get install -y \
# Web server
nginx \
# Database
mariadb-server \
mariadb-client \
# PHP and extensions
php8.4 \
php8.4-fpm \
php8.4-cli \
php8.4-mysql \
php8.4-gd \
php8.4-xml \
php8.4-mbstring \
php8.4-curl \
php8.4-zip \
php8.4-intl \
php8.4-soap \
php8.4-xmlrpc \
php8.4-opcache \
php8.4-redis \
# Security and monitoring
fail2ban \
ufw \
# Cache systems (optional)
redis-server \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Configure SSH
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config \
&& sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config \
&& echo 'root:password' | chpasswd \
&& echo 'ansible:ansible' | chpasswd
# Configure systemd
RUN systemctl enable ssh \
&& systemctl enable nginx \
&& systemctl enable mysql mariadb \
&& systemctl enable php8.4-fpm
# Create web directory structure
RUN mkdir -p /var/www/html \
&& chown -R www-data:www-data /var/www/html \
&& chmod -R 755 /var/www/html
# Copy service startup script
COPY start-services.sh /usr/local/bin/start-services.sh
RUN chmod +x /usr/local/bin/start-services.sh
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost/ || exit 1
# Expose ports
EXPOSE 22 80 443
# Set working directory
WORKDIR /var/www/html
# Use systemd as init system for proper service management
CMD ["/usr/local/bin/start-services.sh"]
# Labels for metadata
LABEL org.opencontainers.image.title="LEMP WordPress Testing Environment"
LABEL org.opencontainers.image.description="Ubuntu 24.04 LTS with Nginx, MySQL, PHP 8.4 for WordPress testing"
LABEL org.opencontainers.image.version="1.0"
LABEL org.opencontainers.image.licenses="MIT"