如何在 Docker 中启用 Apache SSL 以进行本地开发

How to enable Apache SSL in Docker for local development

提问人:Webmill 提问时间:5/15/2023 更新时间:5/15/2023 访问量:372

问:

我正在对我当前的应用程序进行 dockerizing 。我使用了几种服务,但我遇到问题的是 apache 的 https。

我正在使用“php:${8.0}-fpm-alpine”映像,所以我预装了php和apache。我也使用环境 wsl2 与 Ubuntu 和 docker 桌面。

我的 dockerfile 出现以下错误:

[13/17] RUN a2enmod rewrite && a2enmod ssl && a2enmod socache_shmcb:
#0 0.263 /bin/sh: a2enmod: not found

这是我的Dockerfile:

    ARG PHP_VERSION=${PHP_VERSION:-8.1}
FROM php:${PHP_VERSION}-fpm-alpine

RUN apk -U upgrade
RUN apk add --no-cache gcc freetype-dev libjpeg-turbo-dev libpng-dev libzip-dev $PHPIZE_DEPS openssl-dev
RUN apk add --update --no-cache linux-headers
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install opcache gd pdo_mysql zip
RUN docker-php-ext-enable opcache gd zip
RUN docker-php-ext-install mysqli
RUN apk add imap-dev krb5-dev
RUN docker-php-ext-configure imap --with-kerberos --with-imap-ssl \
        && docker-php-ext-install imap \
        && docker-php-ext-enable imap 
        
RUN apk add --update --no-cache --virtual .build-dependencies $PHPIZE_DEPS \
        && pecl install apcu \
        && docker-php-ext-enable apcu \
        && pecl clear-cache \
        && apk del .build-dependencies

RUN set -xe \
    && apk add --update \
        icu \
    && apk add --no-cache --virtual .php-deps \
        make \
    && apk add --no-cache --virtual .build-deps \
        $PHPIZE_DEPS \
        zlib-dev \
        icu-dev \
        g++ \
    && docker-php-ext-configure intl \
    && docker-php-ext-install \
        intl \
    && docker-php-ext-enable intl \
    && { find /usr/local/lib -type f -print0 | xargs -0r strip --strip-all -p 2>/dev/null || true; } \
    && apk del .build-deps \
    && rm -rf /tmp/* /usr/local/lib/php/doc/* /var/cache/apk/*

RUN a2enmod rewrite && a2enmod ssl && a2enmod socache_shmcb
RUN sed -i '/SSLCertificateFile.*snakeoil\.pem/c\SSLCertificateFile \/etc\/ssl\/certs\/mycert.crt' /etc/apache2/sites-available/default-ssl.conf && sed -i '/SSLCertificateKeyFile.*snakeoil\.key/cSSLCertificateKeyFile /etc/ssl/private/mycert.key\' /etc/apache2/sites-available/default-ssl.conf
RUN a2ensite default-ssl
RUN apt-get update && apt-get upgrade -y

ARG ENV=${ENV:-production}

RUN if [ "$ENV" = "dev" ] ; then pecl install xdebug && docker-php-ext-enable xdebug; fi

CMD ["php-fpm"]

这是我的docker-compose文件:

version: '3'

services:
  apache:
    image: httpd:${APACHE_VERSION:-latest}-alpine
    container_name: apache
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./code:/var/www/html
      - ./webserver/httpd.conf:/usr/local/apache2/conf/httpd.conf
      - ./data/logs:/var/log
      - ./ssl/mycert.crt:/etc/ssl/certs/mycert.crt
      - ./ssl/mycert.key:/etc/ssl/private/mycert.key
  php:
    container_name: php
    build:
      context: ./webserver
      args:
        PHP_VERSION: ${PHP_VERSION:-8.1}
        ENV: ${ENV:-production}
    volumes:
      - ./code:/var/www/html
      - ./webserver/php-ini-overrides.ini:/usr/local/etc/php/conf.d/extra.ini
      - ./data/logs:/var/log
      
    # phpmyadmin
  phpmyadmin:
    depends_on:
      - Topsecret
    image: phpmyadmin
    restart: always
    ports:
      - "8090:80"
    environment:
      PMA_HOST: Topsecret
      MYSQL_ROOT_PASSWORD: Nice Try ;P
      
  database:
    image: mariadb:${MARIADB_VERSION:-latest}
    container_name: mariadb
    ports: 
      - ${DB_PUBLIC_PORT:-3306}:3306
    environment: 
      - MYSQL_USER=${MYSQL_USER:-root}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD:-root}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-root}
    volumes: 
      - ./data/database:/var/lib/mariadb
      
networks:
  webserver:

如何修复此错误?谢谢!

docker apache https localhost wsl-2

评论


答: 暂无答案