制作php+swoole的Docker环境

  1. 获取官方PHP7.1-cli镜像,并在此基础上进行修改
  2. 修改apt源为163的源
echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" > /etc/apt/sources.list \
    && echo "deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib" >> /etc/apt/sources.list \
    && echo "deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib" >> /etc/apt/sources.list \
    && echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >> /etc/apt/sources.list \
    && echo "deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib" >> /etc/apt/sources.list \
    && echo "deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib" >> /etc/apt/sources.list \
    && echo "deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib" >> /etc/apt/sources.list
  1. 安装php71-redis扩展
  • pecl方式
pecl install -o -f redis \ && rm -rf /tmp/pear \ && echo "extension=redis.so" > /usr/local/etc/php/conf.d/redis.ini 
  • 源代码编译方式
curl -L -o /tmp/redis.tar.gz https://github.com/phpredis/phpredis/archive/3.1.6.tar.gz \ && tar xfz /tmp/redis.tar.gz \ && rm -r /tmp/redis.tar.gz \ && mv phpredis-3.1.6 /usr/src/php/ext/redis \ && docker-php-ext-install redis 
  1. 安装php-igbinary扩展
    • pecl方式
    pecl install -o -f igbinary \ && rm -rf /tmp/pear \ && docker-php-ext-enable igbinary
    
  2. 安装pdo_mysql扩展
    • 官方脚本方式(pdo_mysql依赖igbinary)
    docker-php-ext-install pdo_mysql
    
  3. 安装swoole v1.10.1
    • 源代码方式
    docker cp /tmp/v1.10.1.zip 5538061f5c26:/tmp/
    unzip /tmp/v1.10.1.zip
    phpize
    ./configure
    make && make install 
    
  4. 完整的Dockerfile
    • Dockerfile
  FROM php:7.1-cli
  
  COPY swoole-v1.10.1.tar.gz /tmp/ 
  WORKDIR /usr/src/swoole
  RUN buildDeps='unzip wget' \
  && echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" > /etc/apt/sources.list \
  && echo "deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib" >> /etc/apt/sources.list \
  && echo "deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib" >> /etc/apt/sources.list \
  && echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >> /etc/apt/sources.list \
  && echo "deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib" >> /etc/apt/sources.list \
  && echo "deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib" >> /etc/apt/sources.list \
  && echo "deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib" >> /etc/apt/sources.list \
  && apt-get update \
  && apt-get install -y $buildDeps \
  #安装igbinary扩展
  && pecl install -o -f igbinary \ 
  && rm -rf /tmp/pear \ 
  && docker-php-ext-enable igbinary \
  #安装redis扩展
  && pecl install -o -f redis \ 
  && rm -rf /tmp/pear \ 
  && docker-php-ext-enable redis \
  #安装mysql扩展
  && docker-php-ext-install pdo_mysql \
  #安装swoole1.10.1
  && tar -xzf /tmp/swoole-v1.10.1.tar.gz -C /usr/src/swoole --strip-components=1 \
  && phpize \
  && ./configure \
  && make \
  && make install \
  && docker-php-ext-enable swoole \
  && rm -rf /var/lib/apt/lists/* \
  && rm -f /tmp/swoole-v1.10.1.tar.gz \
  && rm -r /usr/src/swoole \
  && apt-get purge -y --auto-remove $buildDeps
  WORKDIR /

你可能感兴趣的:(制作php+swoole的Docker环境)