前言抛开Docker的强大功能,今天我们来部署一个本地开发环境。并写几个脚本来提高开发效率。本章使用MacOs系统的Docker演示,其他系统作者已联系。不知道有没有区别。安装傻瓜式安装,这里就不细说了。下载地址如下https://www.docker.com/produc...directory创建一些目录,就像在项目开发中创建Controller、Model、Service一样。我们从目录中整理本地Docker开发环境如下。目录名用于app工程目录,存放源程序的地方。services服务目录,如mysql、php等ssh远程服务器目录,用于链接服务器的web前端目录。通常节点会指向它。部分文件列表文件名Purpose.env配置公共文件docker-compose.ymldocker-composer配置文件hostssystemhosts文件php.shphp相关操作文件start.sh本地环境操作脚本为个人使用,所以命名和规范略有不同。请理解配置服务,将你需要的服务配置到Docker容器中MySQLdocker-composer.ymldb:container_name:'dev_db'build:./services/mysql//指向dockerfile文件环境:MYSQL_ROOT_PASSWORD:${MYSQL_ROOT_PASSWORD}//.env文件配置项ports:-"3306:3306"volumes:-${MYSQL_DATA_PATH}:/var/lib/mysqlCreatemysql-dockerfiletoservices\mysqlDockerfileFROMmysql:5.6MAINTAINERcrazycodes<919342864@qq.com>ADD./config/default.cnf/etc/mysql/conf.d/default.cnfNginxdocker-composer.ymlweb:container_name:'dev_nginx'build:./services/nginxports:-"80:80"depends_on:-phpvolumes_from:-phpvolumes:-${NGINX_VOLUME_CONFIG_PATH}:/etc/nginx/conf.ddns:8.8.8.8DockerfileFROMnginx:latestMAINTAINERcrazycodes<919342864@qq.com>RUNapt-getupdate&&apt-getinstall-yvimsudogccmake解压wgetmercuriallibpcre3-devzlib1g-devlibssl-devdevscriptsdebhelperdpkg-devquiltlsb-releaseCOPYnginx.conf/etc/nginx/nginx.confCOPYnginx-rtmp-module/etc/nginx/nginx-rtmp-moduleCOPYnginx-1.13.9/etc/nginx/nginx-1.13.9WORKDIR/etc/nginx/nginx-1.13.9RUN./configure--prefix=/etc/nginx--sbin-path=/usr/sbin/nginx--modules-path=/usr/lib/nginx/modules--conf-path=/etc/nginx/nginx.conf--error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log--pid-path=/var/run/nginx.pid--lock-path=/var/run/nginx.lock--http-client-body-temp-path=/var/cache/nginx/client_temp--http-proxy-temp-path=/var/cache/nginx/proxy_temp--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp--http-scgi-temp-path=/var/cache/nginx/scgi_temp--user=nginx--group=nginx--with-compat--with-file-aio--with-threads--with-http_addition_module--with-http_auth_request_module--with-http_dav_module--with-http_flv_module--with-http_gunzip_module--with-http_gzip_static_module--with-http_mp4_module--with-http_random_index_module--with-http_realip_module--with-http_secure_link_module--with-http_slice_module--with-http_ssl_module--with-http_stub_status_module--with-http_sub_module--with-http_v2_module--with-mail--with-mail_ssl_module--with-stream--with-stream_realip_module--with-stream_ssl_module--with-stream_ssl_preread_module--with-cc-opt='-g-O2-fdebug-prefix-map=/data/builder/debuild/nginx-1.13.7/debian/debuild-base/nginx-1.13.7=.-specs=/usr/share/dpkg/no-pie-compile.specs-fstack-protector-strong-Wformat-Werror=format-security-Wp,-D_FORTIFY_SOURCE=2-fPIC'--with-ld-opt='-specs=/usr/share/dpkg/no-pie-link.specs-Wl,-z,relro-Wl,-z,now-Wl,--as-needed-pie'--add-module=../nginx-rtmp-moduleRUNmake&&makeinstall站点配置在services\nginx\config里面,你可以正常配置server{listen80;服务器名称本地主机;根/mnt/应用程序/flarum;indexindex.phpindex.htmlindex.htm;location/{try_files$uri$uri//index.php?$query_strinG;}location/api{try_files$uri$uri//api.php?$query_string;}location/admin{try_files$uri$uri//admin.php?$query_string;}location/flarum{全部拒绝;返回404;}location~.php${fastcgi_split_path_info^(.+.php)(/.+)$;fastcgi_passphp:9000;//容器内部,填写容器名称:容器映射端口fastcgi_indexindex.php;包括fastcgi_params;}}PHPdockerfile内容太多,这里就不贴代码了。源码地址会贴在文末。对于其他的学习和应用,代码不仅可以帮助你开发,还可以帮助你提高开发效率。自动化所有工作以更好地反映您的技能。所有的服务器链接文件都放在sshsshset-xsshroot@xxx.xxx.xxx.xxx每次需要链接服务器的时候直接shdev.sh到php.sh里面运行php命令就可以了容器。命令太长,不方便。我们可以把代码放到sh文件中set-xdockerexec-itdev_php/bin/sh-c"cd/mnt/app/${1}&&${2}"这个时候如果需要在PHP中操作容器,可以写shphp.shMy_Blogartisanmigratestart.shstart.sh文件里有一些基本的命令,当然你可以继续扩展你想要的。比如composer的操作,php的操作,mysql的操作等等。详情可点击下方链接查看。致谢通常将许多命令封装到可执行文件中。方便您自己使用。提高开发效率和质量是每个程序员的必备技能。https://github.com/CrazyCodes...这不是一个非常严肃的docker“操作”,请不要在生产环境中使用它。很高兴你来到这里,希望这篇文章能对你有所帮助。谢谢。
