0x03 Docker 搭建lamp环境

  1. 引入
  2. 开始
    1. start.sh
    2. php7.0
    3. php5.6

引入

虽说用docker search能找到一堆lamp,但是用的时候总感觉不顺手,想了下还是自己搭吧

本篇主要讲搭建php5.6和php7.0

开始

需要提前准备好已经安装了mysql的镜像,并按自身情况设置好该镜像的更新源。

start.sh

该脚本用于自启动apache和mysql

#!/bin/bash
service apache2 start
service mysql start
tail -f /dev/null

php7.0

Dockerfile内容如下

# Set up lamp environment (php7.0)

FROM r0co/mysql
MAINTAINER r0co@datsec.cn

# Prepare needed files
COPY ./start.sh /tmp/start.sh

# Update and Install everything in needed
RUN apt-get update \
    && apt-get install -y vim apache2 unzip \
    && apt-get install -y php7.0-* libapache2-mod-php7.0

RUN cp /tmp/start.sh /
RUN chmod +x /start.sh

# Clear idle files
RUN rm -rf /tmp/*

# Start apache2,mysql automatically
CMD ["/bin/sh", "/start.sh"] 

文件树如下

lamp_php7.0
├── Dockerfile
└── start.sh

php5.6

Dockerfile内容如下

# Set up lamp environment (php5.6)

FROM r0co/mysql
MAINTAINER r0co@datsec.cn

# Prepare needed files
COPY ./start.sh /tmp/start.sh

# Update and Install everything in needed
RUN apt-get update \
    && apt-get install -y software-properties-common python-software-properties \
    && LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php -y \
    && apt-get update \
    && apt-get install -y vim apache2 unzip \
    && apt-get install -y php5.6 \
    php5.6-mcrypt \
    php5.6-mbstring \
    php5.6-curl \
    php5.6-cli \
    php5.6-mysql \
    php5.6-gd \
    php5.6-intl \
    php5.6-xsl \
    php5.6-zip \
    php5.6-imap \
    php5.6-pspell \
    php5.6-recode \
    php5.6-sqlite3 \
    php5.6-tidy \
    php5.6-xmlrpc \
    php-gettext \
    php-pear \
    php-memcache \
    && apt-get install -y libapache2-mod-php5.6

RUN cp /tmp/start.sh /
RUN chmod +x /start.sh

# Clear idle files
RUN rm -rf /tmp/*

# Start apache2,mysql automatically
CMD ["/bin/sh", "/start.sh"] 

文件树如下

lamp_php5.6
├── Dockerfile
└── start.sh

如果我的文章能帮到您的话我会很开心.如需转载记得注明出处:)
目录