1.制定特定扩展的php镜像
sudo mkdir -p /www/docker
sudo cd /wwwplant/docker搞笑短信大全
sudo vi dockerfile
from php:7.2-fpm-alpinemaintainer diaocheweiderun d -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/*expo 9000
2.编写yml文件
sudo vi docker-compo.yml
version: '3.1'rvices: 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
rver { listen 80; rver_name localhost; #chart 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 rver error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pro霸气班级口号xy 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 rver 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 -pu mysql;update ur t host='%' where ur='root';flush privileges;
5.创建并且启动容器
docker-compo up -d
6.新建index.php测试mysql连接
<?php$con = mysqli_connect("172.18.0.4", "root", "thisyourpassword", "shop");if ($con) { echo '连接 mysql 成功';} el { echo "连接 mysql 失败: " . mysqli_connect_error();} mysqli_clo($c消费者心理学on);
本文发布于:2023-04-07 14:17:22,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/8cd1c534fd54c2abb568fb15ec966a90.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:docker.doc
本文 PDF 下载地址:docker.pdf
留言与评论(共有 0 条评论) |