docker-compose部署php项目实例详解
网络编程 2021-07-04 23:05www.168986.cn编程入门
在本篇文章里长沙网络推广给大家整理了关于docker-pose部署php项目的相关实例以及代码内容,有需要的朋友们可以学习参考下。
1.制定特定扩展的PHP镜像
sudo mkdir -p //docker
sudo cd //docker
sudo vi Dockerfile
FROM php:7.2-fpm-alpine MAINTAINER diaocheweide RUN sed -i 's/dl-cdn.alpinelinux./mirrors.aliyun./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 \ ptl \ 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-pose.yml
version: '3.1' services: nginx: image: nginx container_name: nginx restart: always ports: - "80:80" - "443:443" volumes: - //data/nginx/conf.d:/etc/nginx/conf.d - //default://default works: csl: ipv4_address: 172.18.0.2 php: image: php:7.2-fpm-alpine-dcwd container_name: php7.2 restart: always volumes: - //default://default works: 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: - //data/mysql/mysql5:/var/lib/mysql #- //data/mysql/mysql5/conf/my.f:/etc/my.f #- //data/mysql/mysql5/init:/docker-entrypoint-initdb.d works: csl: ipv4_address: 172.18.0.4 mysql8: image: mysql:8 container_name: mysql8 restart: always environment: MYSQL_ROOT_PASSWORD: thisyourpassword volumes: - //data/mysql/mysql8:/var/lib/mysql works: csl: ipv4_address: 172.18.0.5 works: csl: driver: bridge ipam: config: - sub: 172.18.0.0/16
3.配置default.conf文件
sudo vi //data/nginx/default.conf
server { listen 80; server_name localhost; #charset koi8-r; #aess_log /var/log/nginx/host.aess.log main; location / { root //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 //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 aess to .htaess 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-pose 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);
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程