平时经常会使用swoole做开发,所以写一个常用开发环境dockerfile。

FROM centos:8

ENV PHP_VERSION=7.4
ENV SWOOLE_VERSION=4.5.9

MAINTAINER [email protected]

#安装依赖包
RUN yum install -y curl wget openssl-devel gcc-c++ make autoconf zip unzip

#配置dnf
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo \
    && yum makecache

#安装php和依赖扩展
RUN dnf module reset php \
    && dnf module -y install php:${PHP_VERSION} \
    && dnf install -y php-devel php-openssl php-json php-mysqlnd php-sockets php-mbstring

#安装swoole
#源码编译安装出现了Cannot find config.m4.报错,暂未解决。
#RUN wget https://pecl.php.net/get/swoole-${SWOOLE_VERSION}.tgz -O swoole.tar \
#    && mkdir -p swoole \
#    && tar -xvf swoole.tar -C swoole \
#    && rm swoole.tar \
#    && ( \
#    cd swoole \
#    && phpize \
#    && ./configure --enable-openssl --enable-http2 --enable-swoole-json \
#    && make \
#    && make install \
#    ) \
#    && echo "extension=swoole" > /etc/php.d/30-swoole.ini \
#    && rm -r swoole

#安装pecl
RUN wget http://pear.php.net/go-pear.phar \
    && php go-pear.phar
#使用pecl安装swoole
RUN pecl install swoole \
    && echo "extension=swoole" > /etc/php.d/30-swoole.ini \
    && echo "swoole.use_shortname=off" >> /etc/php.d/30-swoole.ini

#安装composer
RUN curl -sS https://getcomposer.org/installer | php \
    && mv composer.phar /usr/bin/composer \
    && composer config -g repo.packagist composer https://mirrors.cloud.tencent.com/composer/

#安装redis和php-redis
RUN dnf install -y redis \
    && pecl install redis \
    && echo "extension=redis" > /etc/php.d/30-redis.ini
#安装mysql
RUN dnf install -y mysql-server

#执行系统进程(不然无法使用systemctl等系统命令)
ENTRYPOINT ["/usr/sbin/init"]
EXPOSE 9501

构建镜像

docker build -f Dockerfile -t centos8/swoole4.5.9:swoole .

注意:如果不使用-f指定dockerfile路径,Dockerfile文件命名D要大写

运行容器

docker run -itd --privileged=true -v D:\docker:/docker -p 10022:22 -p 13306:3306 -p 16379:6379 -p 10080:80 -p 9500:9500 -p 9501:9501 d359750b0627

注意:一定要加上--privileged获取真正的root权限

07-19 13:19