基础的环境已在文章中搭建了,现在是在这个基础上在搭建easyswoole开发环境
主要要修改的地方是dnmp包里面的docker-compose.yml修改:
version: '3'networks:# frontend:# driver: ${NETWORKS_DRIVER} backend: driver: ${NETWORKS_DRIVER}#volumes:# mysql:# driver: ${VOLUMES_DRIVER}# memcached:# driver: ${VOLUMES_DRIVER}# redis:# driver: ${VOLUMES_DRIVER}# mongo:# driver: ${VOLUMES_DRIVER}services:# php-client注释掉# php-client:# image: "swoole:4.1.2"# build:# context: ./php# ports:# - "9502:9502"# networks:# - backend# volumes:# - ${APP_CODE_PATH_HOST}:/app:rw# command: php /app/swoole/examples/http/server.php start php: image: "swoole:4.1.2" build: context: ./php ports: - "9501:9501" networks: - backend volumes: - ${APP_CODE_PATH_HOST}:/app:rw command: /app/easyswoole/vendor/bin/easyswoole start### PHP-FPM ############################################## php-fpm: build: context: ./php-fpm args: - LARADOCK_PHP_VERSION=${PHP_VERSION} - INSTALL_XDEBUG=${PHP_FPM_INSTALL_XDEBUG} - INSTALL_PHPDBG=${PHP_FPM_INSTALL_PHPDBG} - INSTALL_BLACKFIRE=${INSTALL_BLACKFIRE} - INSTALL_SSH2=${PHP_FPM_INSTALL_SSH2} - INSTALL_SOAP=${PHP_FPM_INSTALL_SOAP} - INSTALL_IMAP=${PHP_FPM_INSTALL_IMAP} - INSTALL_MONGO=${PHP_FPM_INSTALL_MONGO} - INSTALL_AMQP=${PHP_FPM_INSTALL_AMQP} - INSTALL_MSSQL=${PHP_FPM_INSTALL_MSSQL} - INSTALL_ZIP_ARCHIVE=${PHP_FPM_INSTALL_ZIP_ARCHIVE} - INSTALL_BCMATH=${PHP_FPM_INSTALL_BCMATH} - INSTALL_GMP=${PHP_FPM_INSTALL_GMP} - INSTALL_PHPREDIS=${PHP_FPM_INSTALL_PHPREDIS} - INSTALL_MEMCACHED=${PHP_FPM_INSTALL_MEMCACHED} - INSTALL_OPCACHE=${PHP_FPM_INSTALL_OPCACHE} - INSTALL_EXIF=${PHP_FPM_INSTALL_EXIF} - INSTALL_AEROSPIKE=${PHP_FPM_INSTALL_AEROSPIKE} - AEROSPIKE_PHP_REPOSITORY=${AEROSPIKE_PHP_REPOSITORY} - INSTALL_MYSQLI=${PHP_FPM_INSTALL_MYSQLI} - INSTALL_PGSQL=${PHP_FPM_INSTALL_PGSQL} - INSTALL_PG_CLIENT=${PHP_FPM_INSTALL_PG_CLIENT} - INSTALL_TOKENIZER=${PHP_FPM_INSTALL_TOKENIZER} - INSTALL_INTL=${PHP_FPM_INSTALL_INTL} - INSTALL_GHOSTSCRIPT=${PHP_FPM_INSTALL_GHOSTSCRIPT} - INSTALL_LDAP=${PHP_FPM_INSTALL_LDAP} - INSTALL_SWOOLE=${PHP_FPM_INSTALL_SWOOLE} - SWOOLE_VERSION=${PHP_SWOOLE_VERSION} - INSTALL_IMAGE_OPTIMIZERS=${PHP_FPM_INSTALL_IMAGE_OPTIMIZERS} - INSTALL_IMAGEMAGICK=${PHP_FPM_INSTALL_IMAGEMAGICK} - INSTALL_CALENDAR=${PHP_FPM_INSTALL_CALENDAR} - INSTALL_FAKETIME=${PHP_FPM_INSTALL_FAKETIME} - INSTALL_IONCUBE=${PHP_FPM_INSTALL_IONCUBE} volumes: - ./php-fpm/php${PHP_VERSION}.ini:/usr/local/etc/php/php.ini - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER} expose: - "9000" depends_on: - php environment: - PHP_IDE_CONFIG=${PHP_IDE_CONFIG} - FAKETIME=${PHP_FPM_FAKETIME} networks: - backend## NGINX Server ######################################### nginx: build: context: ./nginx args: - PHP_UPSTREAM_CONTAINER=${NGINX_PHP_UPSTREAM_CONTAINER} - PHP_UPSTREAM_PORT=${NGINX_PHP_UPSTREAM_PORT} volumes: - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER} - ${NGINX_HOST_LOG_PATH}:/var/log/nginx - ${NGINX_SITES_PATH}:/etc/nginx/sites-available:rw ports: - "${NGINX_HOST_HTTP_PORT}:80" - "${NGINX_HOST_HTTPS_PORT}:443" depends_on: - php - php-fpm networks:# - frontend - backend### MySQL ################################################# mysql:# build:# context: ./mysql# args:# - MYSQL_VERSION=${MYSQL_VERSION}# environment:# - MYSQL_DATABASE=${MYSQL_DATABASE}# - MYSQL_USER=${MYSQL_USER}# - MYSQL_PASSWORD=${MYSQL_PASSWORD}# - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}# - TZ=${WORKSPACE_TIMEZONE}# volumes:## - ${DATA_PATH_HOST}/mysql:/var/lib/mysql# - mysql:/var/lib/mysql# - ${MYSQL_ENTRYPOINT_INITDB}:/docker-entrypoint-initdb.d# ports:# - "${MYSQL_PORT}:3306"# networks:# - backend### MongoDB ############################################### mongo:# build: ./mongo# ports:# - "${MONGODB_PORT}:27017"# volumes:## - ${DATA_PATH_HOST}/mongo:/data/db# - mongo:/data/db# networks:# - backend### Redis ################################################# redis:# build: ./redis# volumes:# - ${DATA_PATH_HOST}/redis:/data# ports:# - "${REDIS_PORT}:6379"# networks:# - backend### Memcached ############################################# memcached:# build: ./memcached# volumes:# - ${DATA_PATH_HOST}/memcached:/var/lib/memcached# ports:# - "${MEMCACHED_HOST_PORT}:11211"# depends_on:# - php# networks:# - backend
宿主机本机目录上新建一个sh脚本文件,用于运行安装easyswoole,并命名为easyswoole_install.sh详细代码如下
#!/bin/sh# swoole image must contain php composerswoole_img="swoole:4.1.2"container_code_path="/app"work_dir="/www"docker_compose_file_path="/www/dnmp"cur_dir=$(pwd)if [ -d ${work_dir}/easyswoole ]; then sudo rm -rf ${work_dir}/easyswoolefiInit_Easyswoole(){ docker run --rm --net=host -v ${work_dir}:${container_code_path}:rw composer sh -c "composer config -g repo.packagist composer https://packagist.laravel-china.org && cd ${container_code_path} && composer create-project easyswoole/app easyswoole"}Install_Easyswoole(){ docker run --rm --net=host -v ${work_dir}:${container_code_path}:rw ${swoole_img} sh -c "${container_code_path}/easyswoole/vendor/bin/easyswoole install"}Init_EasyswooleInstall_Easyswoolecd ${docker_compose_file_path}docker-compose up -ddocker-compose ps
以上的word_dir为宿主机的工作目录,/www/dnmp为dnmp环境中的docker-compose.yml目录;
使用xshell进行连接docker虚拟机,进入到easyswoole_install.sh所在目录,运行:
./easyswoole_install.sh
easyswoole安装成功后,打开Docker Quickstart Terminal.exe
进入到dnmp目录,运行
docker-compose down
再运行
docker-compose up -d
然后查看容器是否全部启动
docker-compse ps
发现已经全部启动,在win7宿主机进行访问http://localhost:9501/,已经可以正常使用了
接下来就可以开始使用easyswoole
PS:若是修改easyswoole宿主机代码,要生效的话,需要在docker虚拟机上reload才能生效
docker-compose exec php easyswoole/vendor/bin/easyswoole reload