好物优选点击查看详情 京东购买

暂无内容

用docker创建wordpress+nginx+php+mysql架构(1)

搭建用docker创建wordpress+nginx+php+mysql架构

1.第一:构建php镜像并且启动php容器

1、下载wordpress包 [root@Centos7 opt]# wget https://wordpress.org/latest.zip 2、解压 [root@Centos7 opt]# unzip latest.zip 3、下载php源码包(不能用7版的官方镜像用5.6的,因为我们还需要添加一个模块,所以,我们下载源码包编译安装) [root@Centos7 opt]# wget https://www.php.net/distributions/php-5.6.40.tar.gz 4.在容器编译安装PHP(如果遇到容器内部没网络,可以重启docker) root@docker opt]# docker run -it --network=yzy --name=nginxyzy centos:7 bash #将PHP包传到容器内 [root@docker opt]# docker cp php-5.6.40.tar.gz 3664c22eff21:/opt [root@3664c22eff21 /]# ls /opt php-5.6.40.tar.gz [root@3664c22eff21 opt]# tar xf php-5.6.40.tar.gz [root@3664c22eff21 opt]# cd php-5.6.40 [root@3664c22eff21 php-5.6.40]# ./configure -h |grep mysql --with-mysql=DIR Include MySQL support. DIR is the MySQL base mysqlnd the MySQL native driver will be used #安装依赖 [root@3664c22eff21 /]# yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers [root@66f1bcff51bd opt]# tar -xf php-5.6.40.tar.gz [root@66f1bcff51bd php-5.6.40]# ./configure --with-mysql -h |grep fpm --enable-fpm Enable building of the fpm SAPI executable #开始编译安装 [root@66f1bcff51bd php-5.6.40]# ./configure --with-mysql --enable-fpm #标记一下是enable不是enabled [root@66f1bcff51bd php-5.6.40]#make -j && make install(其实直接用make && make install) #检测php编译完成后,有没有这个mysql扩展库(# php -m 显示已经编译安装的模块),如果有表明安装成功了,没有就是失败了 [root@66f1bcff51bd php-5.6.40]# php -m | grep mysql mysql mysqlnd #将php配置文件发到/usr/local/lib这个自定义编译的配置文件扔下的地方 root@66f1bcff51bd php-5.6.40]# cp php.ini-development /usr/local/lib/php.ini #检测显示配置文件名称在/usr/local/lib下就有了 root@66f1bcff51bd php-5.6.40]# php --ini Configuration File (php.ini) Path: /usr/local/lib Loaded Configuration File: /usr/local/lib/php.ini #保存容器为镜像 [root@docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 66f1bcff51bd centos:7 "bash" 26 hours ago Up About an hour nginxyzy [root@docker ~]# docker commit -a '尉朝阳' -m '编译的特殊的PHP包' 66f1bcff51bd php:v1-fpm-mysql sha256:0c7825ac87308afb70437ead57fad80d5708e3909df4d12c3632f13cf2009bf0 #生成我们自己制作的镜像(在php里加入了部分mysql模块) [root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE php v1-fpm-mysql 0c7825ac8730 10 minutes ago 1.05GB #为刚生成的镜像打标签 标签:registry.cn-shanghai.aliyuncs.com/libary1/php:v1-fpm-mysql [root@docker ~]# docker tag 0c7825ac8730 registry.cn-shanghai.aliyuncs.com/libary1/php:v1-fpm-mysql #登录我们的阿里云 [root@docker ~]# docker login -u鲜卑柱石 registry.cn-shanghai.aliyuncs.com Password: Login Succeeded [root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE php v1-fpm-mysql 0c7825ac8730 17 minutes ago 1.05GB registry.cn-shanghai.aliyuncs.com/libary1/php v1-fpm-mysql 0c7825ac8730 17 minutes ago 1.05GB #上传我们打打完标签的镜像到我们阿里云指定的仓库空间 [root@docker ~]# docker push registry.cn-shanghai.aliyuncs.com/libary1/php:v1-fpm-mysql [root@docker ~]# find / -name 'php-fpm.conf*' /var/lib/docker/overlay2/d38e3889c4e1c07307f517f0f57ed878d24f375ff48db0c063c6160ae27331ec/merged/usr/local/etc/php-fpm.conf.default [root@docker php]# docker cp 66f1bcff51bd:/usr/local/etc/php-fpm.conf.default . [root@docker php]# vim php-fpm.conf.default request_terminate_timeout = 0 listen = 9000 user = www group = www [root@docker php]# mv php-fpm.conf.default php-fpm.conf [root@docker php]# ls Dockerfile php-fpm.conf [root@docker php]# cat Dockerfile FROM registry.cn-shanghai.aliyuncs.com/libary1/php:v1-fpm-mysql #记住:一定要带镜像的版本号 RUN useradd www ADD php-fpm.conf /usr/local/etc/ EXPOSE 9000 CMD ["php-fpm","-F"] #基于Dockerfile 构建镜像 root@docker php]# docker build -t lnmpphp:v1 . Successfully built 3cac41b25eb8 Successfully tagged lnmpphp:v1 #在容器php内部运行php-fpm -F命令 [root@66f1bcff51bd ~]# cd /usr/local/etc/p pear.conf php-fpm.conf.default [root@66f1bcff51bd ~]# cd /usr/local/etc/ [root@66f1bcff51bd etc]# ls pear.conf php-fpm.conf.default [root@66f1bcff51bd etc]# mv php-fpm.conf.default php-fpm.conf [root@66f1bcff51bd etc]# ls pear.conf php-fpm.conf [root@66f1bcff51bd etc]# php-fpm -F [27-Mar-2021 19:29:55] NOTICE: fpm is running, pid 40 [27-Mar-2021 19:29:55] NOTICE: ready to handle connections #启动刚刚构建的镜像lnmpphp:v1,启动成功! [root@docker ~]# docker run -d lnmpphp:v1 c73d20255cfc63bfa954afe448ea98e38a8fa5eea764c2a17191fbe3768af18b [root@docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c73d20255cfc lnmpphp:v1 "php-fpm -F" 3 seconds ago Up 3 seconds 9000/tcp agitated_lovelace 66f1bcff51bd centos:7 "bash" 2 days ago Up 37 minutes nginxyzy 

第二:构建mysql镜像

#启动数据库镜像容器 [root@docker ~]# docker pull mysql:5.7 [root@docker ~]# docker run -d --network=yzy --name=mysql -e MYSQL_ROOT_PASSWORD=123 mysql:5.7 [root@docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c4c5c669565c mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp mysql [root@docker ~]# docker exec -it c4c5c669565c bash root@c4c5c669565c:/# mysql -uroot -p123 mysql> create database wordpress; Query OK, 1 row affected (0.00 sec) mysql> \q Bye 

第三:启动nginx镜像容器

1.#分别准备下面三个配置文件并且修改相关参数和用户

[root@docker nginx]# ls default.conf Dockerfile nginx.conf nginx.repo 构建nginx镜像 ## Dockerfile FROM centos:7 ADD nginx.repo /etc/yum.repos.d/ RUN yum install nginx -y ADD default.conf /etc/nginx/conf.d/ ADD nginx.conf /etc/nginx/ WORKDIR /usr/share/nginx/ EXPOSE 80 443 RUN useradd www CMD nginx -g "daemon off;" ## default.conf server { listen 80; listen [::]:80; server_name localhost; location / { root /usr/share/nginx/html; index index.php index.html index.htm; } location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass php:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name; include fastcgi_params; } } ## nginx.conf user www; ## nginx.repo [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true 

2.基于构建镜像配置文件构建镜像

[root@docker nginx]# docker build -t lnmpnginx:v1 . Successfully built 44905fb7742a Successfully tagged lnmpnginx:v1 

3.针对自定义镜像创建容器同时指定访问端口 和 挂载文件

[root@docker ~]# docker run -d -p 80:80 -v /docker/wordpress/:/usr/share/nginx/html --network=yzy --name=ngix lnmpnginx:v1 b8da712e101e185a6091a78f705551126ad731000e8c42c5bf4b57ff3fcd8c93 

4.针对构建好的镜像创建容器

[root@docker docker]# docker run -d -v /docker/wordpress/:/usr/share/nginx/html --network=yzy --name=php lnmpphp:v1 

5.将wordpress挂载到php站点上

[root@docker docker]#docker run -d -v /docker/wordpress/:/usr/share/nginx/html --network=yzy --name=php lnmpphp:v1 
访问10.0.0.81测试!不好意思失败了,但总体明白了整个框架构建的意义 
  1. List item

原文链接:https://blog.csdn.net/ximanxue/article/details/115326069?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168994674516800182116245%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168994674516800182116245&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-11-115326069-null-null.268%5Ev1%5Ekoosearch&utm_term=docker%E3%80%81wordpress%E3%80%81wordpress%E5%BB%BA%E7%AB%99%E3%80%81wordpress%E4%B8%BB%E9%A2%98%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享