我正在尝试了解 Docker 多阶段构建。我有 Docker 工具箱 18.03,所以我可以运行它们。查看文档后,我的第一次尝试是使用 Python 3.7 和 Php-apache 构建图像。所以我写了这个 Dockerfile:
FROM python:3.7.0-stretch
FROM php:7-apache-stretch
RUN docker-php-ext-install mbstring mysqli pdo pdo_mysql
RUN a2enmod rewrite
# Enable SSL
RUN a2enmod ssl
RUN mkdir /etc/apache2/ssl
ADD server.crt /etc/apache2/ssl/
ADD server.key /etc/apache2/ssl/
ADD default-ssl.conf /etc/apache2/sites-available/
RUN a2ensite default-ssl
EXPOSE 443
RUN echo 'log_errors = On' >> /usr/local/etc/php/php.ini
然后我运行docker build .
并成功构建它:
Sending build context to Docker daemon 12.29kB
Step 1/12 : FROM python:3.7.0-stretch
---> 825141134528
Step 2/12 : FROM php:7-apache-stretch
---> 5e5a59788e34
Step 3/12 : RUN docker-php-ext-install mbstring mysqli pdo pdo_mysql
---> Using cache
---> bf6b095ac6d3
Step 4/12 : RUN a2enmod rewrite
---> Using cache
---> d3443d0e8d97
Step 5/12 : RUN a2enmod ssl
---> Running in edd0a15406db
Considering dependency setenvif for ssl:
Module setenvif already enabled
Considering dependency mime for ssl:
Module mime already enabled
Considering dependency socache_shmcb for ssl:
Enabling module socache_shmcb.
Enabling module ssl.
See /usr/share/doc/apache2/README.Debian.gz on how to configure SSL and create self-signed certificates.
To activate the new configuration, you need to run:
service apache2 restart
Removing intermediate container edd0a15406db
---> a301c3a3ca78
Step 6/12 : RUN mkdir /etc/apache2/ssl
---> Running in 59621555d753
Removing intermediate container 59621555d753
---> db74733784c3
Step 7/12 : ADD server.crt /etc/apache2/ssl/
---> db3715192748
Step 8/12 : ADD server.key /etc/apache2/ssl/
---> f6206d6b2d5e
Step 9/12 : ADD default-ssl.conf /etc/apache2/sites-available/
---> 0fa5dd62c854
Step 10/12 : RUN a2ensite default-ssl
---> Running in 7ab353bca552
Enabling site default-ssl.
To activate the new configuration, you need to run:
service apache2 reload
Removing intermediate container 7ab353bca552
---> 53336ee4133d
Step 11/12 : EXPOSE 443
---> Running in 0530749e96b3
Removing intermediate container 0530749e96b3
---> 53b56723dd81
Step 12/12 : RUN echo 'log_errors = On' >> /usr/local/etc/php/php.ini
---> Running in 8bd7c50715c3
Removing intermediate container 8bd7c50715c3
---> d456abb9ee67
Successfully built d456abb9ee67
然后我为它创建了容器并运行。它启动并保持启动,所以我尝试进入容器的 bash 并有惊喜,php 和 apache 工作正常,python 甚至不存在。我在 Dockerfile 中缺少什么?