docker-compose怎么编写(docker-compose部署php项目实例详解)
类别:编程学习 浏览量:1049
时间:2021-11-05 14:47:30 docker-compose怎么编写
docker-compose部署php项目实例详解1.制定特定扩展的PHP镜像
|
sudo mkdir -p /www/docker |
|
sudo cd /www/docker |
|
sudo vi Dockerfile |
|
FROM php:7.2-fpm-alpine MAINTAINER diaocheweide RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories RUN 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.5 networks: 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 bash mysql -u root -p use 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 ); |
原文链接:https://blog.csdn.net/JingbangLiang/article/details/82756825
标签:docker-compo PHP
您可能感兴趣
- docker-compose怎么编写(docker-compose部署php项目实例详解)
- docker-compose启动单个容器(docker-compose快速搭建docker私有仓库的步骤)
- docker部署kafka认证(docker-compose部署zk+kafka+storm集群的实现)
- dockerfile构建mysql镜像并初始化(docker-compose基于MySQL8部署项目的实现)
- docker-compose命令(docker-compose教程之安装使用和快速入门)
- docker-compose 开发代码(Docker Compose多容器部署的实现)
- dockercompose的常用命令的作用(PIP安装docker-compose超时问题解决方案)
- idea集成docker-compose(IDEA 集成 docker 实现远程部署的详细步骤)
- 如何编写docker-compose(使用Docker Compose搭建 Confluence的教程)
- docker compose 与docker区别(windows安装Docker与docker-compose套装的详细教程)
- docker-compose怎么被执行的(Docker Compose一键ELK部署的方法实现)
- docker-compose 如何启动(docker compose部署主从复制的实现)
- docker容器编排入门教程(laradock环境docker-compose操作详解)
- docker-compose查看服务状态(Docker+DockerCompose封装web应用的方法步骤)
- dockerspringboot一键部署(docker-compose镜像发布springboot项目的流程分析)
- docker-compose启动超时(docker compose idea CreateProcess error=2 系统找不到指定的文件的问题)
- 四川旅游攻略(四川旅游攻略自由行攻略)
- 上海迪士尼攻略(上海迪士尼攻略旅游)
- 哪里可以看熊猫(成都哪里可以看熊猫)
- oppo手机的三种录屏方法,你知道有哪些吗(oppo手机的三种录屏方法)
- 吉林神秘传染链跨省 传染源尚未找到,舒兰 封城(吉林神秘传染链跨省)
- 吉林舒兰 封城 聚集性疫情传播链已延至沈阳,有一个细节让人忧心(吉林舒兰封城)
热门推荐
- mysql索引失效怎么办(MySQL选错索引的原因以及解决方案)
- python基础编程函数参数(详解Python 函数如何重载?)
- css里margin是什么意思(正确理解CSS中的margin合并的用法)
- 哪里有免费的云服务器价格实惠(安全的美国云服务器哪里比较便宜?)
- nginx负载均衡原理3种(Nginx负载均衡以及动静分离的原理与配置)
- mysql中group_concat
- linux解压zip文件的命令(Linux gzip 命令的使用)
- WebStorm前端开发工具
- SqlServer 按时间段查询问题(SqlServer 按时间段查询问题)
- 云服务器主要内容(云服务器的应用优势分析,你知道有哪些优势吗?)
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9