我正在为旧系统设置新的测试环境。希望自己构建 dockerfile 或“克隆”当前的生产服务器。
我正在使用 Docker 桌面社区(v. 2.0.0.3),我维护的系统是 Ubuntu 18.04 上带有 mysql 5.7 的 php 7.2 webapp。我选择制作一张 ubuntu 映像,并通过 dockerfile 中的 RUN 命令安装 php 和 mysql。
FROM ubuntu:18.04
LABEL author="John Doe"
LABEL maintainer="john.doe@example.com"
ENV DEBIAN_FRONTEND noninteractive
# Install basics
RUN apt-get update
RUN apt-get install -y software-properties-common && \
add-apt-repository ppa:ondrej/php && apt-get update && \
add-apt-repository ppa:ondrej/apache2 && apt-get update
RUN apt-get install -y --force-yes curl nano apt-utils
ENV MYSQL_ROOT_PASSWORD=my-secret-pw
RUN apt-get update
RUN apt-get -y --allow-unauthenticated install mysql-server-5.7
RUN usermod -d /var/run/mysqld/ mysql
# Install PHP 7.2
RUN apt-get install -y --allow-unauthenticated php7.2
RUN apt-get install -y --allow-unauthenticated php7.2-mysqli \
php7.2-mysqlnd \
php7.2-mbstring \
php7.2-bz2 \
php7.2-zip \
php7.2-curl \
php7.2-gd \
php7.2-gettext \
php7.2-mbstring \
php7.2-mysql \
php-pear \
php-php-gettext \
php-phpseclib \
php-tcpdf \
php7.2-xml \
php7.2-common \
php7.2-json \
php7.2-readline \
php7.2-opcache \
php7.2-xml
# Enable apache mods.
RUN a2enmod php7.2
RUN a2enmod rewrite
# Manually set up the apache environment variables
ENV APACHE_LOG_DIR /var/log/apache2
# ENV PHP_LOG_DIR /var/log/php
# ENV MYSQL_LOG_DIR /var/log/mysql
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2/apache2.pid
ENV MYSQL_PID_FILE /var/run/mysqld/mysqld.pid
WORKDIR /var/www/example.com/public_html/
RUN mkdir /var/log/apache2/
# Update the default apache site with the config we created.
# Conf locations
# php: /etc/php/7.2/apache2/php.ini
# apache: /etc/apache2/apache2.conf
# mysql: /etc/mysql/mysql.cnf
# RUN cp -R * /etc/apache2 /var/www/conf/apache2
COPY conf/apache_example/apache2 /etc/apache2
# RUN cp -R * /etc/php /var/www/conf/php
COPY conf/php_example/7.2 /etc/php/7.2
# RUN cp -R * /etc/mysql /var/www/conf/mysql
COPY conf/mysql_example /etc/mysql
COPY src /var/www/example.com/public_html
# Expose apache.
EXPOSE 80
EXPOSE 8080
EXPOSE 443
EXPOSE 3306
# By default start up apache in the foreground, override with /bin/bash for interative.
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
我的期望是能够启动遗留系统并在我的机器上本地测试新的和更改的代码,然后再将其上传到生产服务器。