各类知识收集,PHP技术分享与解决方案各类知识收集,PHP技术分享与解决方案各类知识收集,PHP技术分享与解决方案

Str Tom,为分享PHP技术和解决方案,贡献一份自己的力量!
收藏本站(不迷路),每天更新好文章!
当前位置:首页 > CMS教程 > PHP

docker-compose部署php项目

管理员 2023-09-05
PHP
113

docker-compose部署php项目

内容导读

收集整理的这篇技术教程文章主要介绍了docker-compose部署php项目,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3653字,纯文字阅读大概需要6分钟

内容图文

1.制定特定扩展的PHP镜像
sudo mkdir -p /www/docker
sudo cd /www/docker
sudo vi Dockerfile
FROM php:7.2-fpm-alpineMAINTAINER diaocheweideRUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositoriesRUN apk update && apk add --no-cache --virtual .build-deps         $PHPIZE_DEPS         curl-dev         imagemagick-dev         libtool         libxml2-dev         postgresql-dev         sqlite-dev         libmcrypt-dev         freetype-dev         libjpeg-turbo-dev         libpng-dev     && apk add --no-cache         curl         imagemagick  mysql-client         postgresql-libs     && pecl install imagick     && pecl install mcrypt-1.0.1     && docker-php-ext-install zip     && docker-php-ext-install pdo_mysql     && docker-php-ext-install opcache     && docker-php-ext-install mysqli     && docker-php-ext-enable mcrypt     && docker-php-ext-enable imagick     && docker-php-ext-install         curl         mbstring         pdo         pdo_mysql         pdo_pgsql         pdo_sqlite         pcntl         tokenizer         xml         zip         && docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" iconv     && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/     && docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" gd     && pecl install -o -f redis     && rm -rf /tmp/pear     && docker-php-ext-enable redis     && rm -r /var/cache/apk/*EXPOSE 9000

2.编写yml文件

sudo vi docker-compose.yml
version: '3.1'services:  nginx:    image: nginx    container_name: nginx    restart: always    ports:      - "80:80"      - "443:443"    volumes:      - /www/data/nginx/conf.d:/etc/nginx/conf.d      - /www/default:/www/default    networks:      csl:        ipv4_address: 172.18.0.2   php:    image: php:7.2-fpm-alpine-dcwd    container_name: php7.2    restart: always    volumes:      - /www/default:/www/default    networks:      csl:        ipv4_address: 172.18.0.3 mysql5:    image: mysql:5.7    container_name: mysql5    restart: always    ports:      - "3306:3306"    environment:      MYSQL_ROOT_PASSWORD: thisyourpassword    volumes:      - /www/data/mysql/mysql5:/var/lib/mysql #- /www/data/mysql/mysql5/conf/my.cnf:/etc/my.cnf      #- /www/data/mysql/mysql5/init:/docker-entrypoint-initdb.d    networks:      csl:        ipv4_address: 172.18.0.4 mysql8:    image: mysql:8    container_name: mysql8    restart: always    environment:      MYSQL_ROOT_PASSWORD: thisyourpassword    volumes:      - /www/data/mysql/mysql8:/var/lib/mysql networks:      csl:        ipv4_address: 172.18.0.5networks:  csl:    driver: bridge    ipam:      config:        - subnet: 172.18.0.0/16

3.配置default.conf文件,拷贝这一步请参考上一篇文章

sudo vi /www/data/nginx/default.conf
server {    listen       80;    server_name  localhost;    #charset koi8-r;    #access_log  /var/log/nginx/host.access.log  main;    location / {        root   /www/default;        index  index.php index.html index.htm;    }    #error_page  404              /404.html;    # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   /usr/share/nginx/html;    }    # proxy the PHP scripts to Apache listening on 127.0.0.1:80    #    #location ~ .php$ {    #    proxy_pass   http://127.0.0.1;    #}    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    #    location ~ .php$ {        root           /www/default;        fastcgi_pass   php7.2:9000;#php容器名或者php容器ip        fastcgi_index  index.php;        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        include        fastcgi_params;    }    # deny access to .htaccess files, if Apache's document root    # concurs with nginx's one    #    #location ~ /.ht {    #    deny  all;    #}}

4.修改mysql允许远程连接并新建数据库

docker exec -it mysql5 bashmysql -u root -puse mysql;update user set host='%' where user='root';flush privileges;

5.创建并且启动容器

docker-compose up -d

6.新建index.php测试mysql连接

<?php$con = mysqli_connect("172.18.0.4", "root", "thisyourpassword", "shop");if ($con) {    echo '连接 MYSQL 成功';} else {    echo "连接 MySQL 失败: " . mysqli_connect_error();} mysqli_close($con);

以上就是docker-compose部署php项目的详细内容,更多请关注Gxl网其它相关文章!

内容总结

以上是为您收集整理的docker-compose部署php项目全部内容,希望文章能够帮你解决docker-compose部署php项目所遇到的程序开发问题。 如果觉得技术教程内容还不错,欢迎将网站推荐给程序员好友。

内容备注

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

相关推荐

扫码关注

qrcode

QQ交谈

回顶部