- Docker-compose部署WordPress
- 一. 准备部分
- 二. 编写启动脚本
- 三.nginx挂载
- 四. 启动
- 附录
- test1 安装mysql
- test2 编写脚本
- test3 启动
cd <span class="token operator">/</span>home mkdir <span class="token operator">-</span>p wordpress<span class="token operator">/</span><span class="token punctuation">{</span>db<span class="token punctuation">,</span>db_data<span class="token punctuation">}</span> cd wordpress touch docker<span class="token operator">-</span>compose<span class="token punctuation">.</span>yml cd <span class="token operator">/</span>home<span class="token operator">/</span>wordpress<span class="token operator">/</span>db touch mysql<span class="token punctuation">.</span>cnfcd <span class="token operator">/</span>home mkdir <span class="token operator">-</span>p wordpress<span class="token operator">/</span><span class="token punctuation">{</span>db<span class="token punctuation">,</span>db_data<span class="token punctuation">}</span> cd wordpress touch docker<span class="token operator">-</span>compose<span class="token punctuation">.</span>yml cd <span class="token operator">/</span>home<span class="token operator">/</span>wordpress<span class="token operator">/</span>db touch mysql<span class="token punctuation">.</span>cnfcd /home mkdir -p wordpress/{db,db_data} cd wordpress touch docker-compose.yml cd /home/wordpress/db touch mysql.cnf
此时目录结构
mysql配置
<span class="token function">vi</span> /home/wordpress/db/mysql.cnf <span class="token punctuation">[</span>mysqld<span class="token punctuation">]</span> explicit_defaults_for_timestamp<span class="token operator">=</span>true wait_timeout<span class="token operator">=</span>86400 interactive_timeout<span class="token operator">=</span>7200<span class="token function">vi</span> /home/wordpress/db/mysql.cnf <span class="token punctuation">[</span>mysqld<span class="token punctuation">]</span> explicit_defaults_for_timestamp<span class="token operator">=</span>true wait_timeout<span class="token operator">=</span>86400 interactive_timeout<span class="token operator">=</span>7200vi /home/wordpress/db/mysql.cnf [mysqld] explicit_defaults_for_timestamp=true wait_timeout=86400 interactive_timeout=7200
Docker-compose.yml
<span class="token function">vi</span> /home/wordpress/docker-compose.yml version: <span class="token string">'2'</span> services: wordpress: image: wordpress ports: - <span class="token string">"8080:80"</span> environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: yourpassword db: image: mysql:5.7 volumes: - ./db_data:/var/lib/mysql - ./db/mysql.cnf:/etc/my.cnf restart: always environment: MYSQL_ROOT_PASSWOD: yourpassword<span class="token function">vi</span> /home/wordpress/docker-compose.yml version: <span class="token string">'2'</span> services: wordpress: image: wordpress ports: - <span class="token string">"8080:80"</span> environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: yourpassword db: image: mysql:5.7 volumes: - ./db_data:/var/lib/mysql - ./db/mysql.cnf:/etc/my.cnf restart: always environment: MYSQL_ROOT_PASSWOD: yourpasswordvi /home/wordpress/docker-compose.yml version: '2' services: wordpress: image: wordpress ports: - "8080:80" environment: WORDPRESS_DB_HOST: db WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: root WORDPRESS_DB_PASSWORD: yourpassword db: image: mysql:5.7 volumes: - ./db_data:/var/lib/mysql - ./db/mysql.cnf:/etc/my.cnf restart: always environment: MYSQL_ROOT_PASSWOD: yourpassword
<span class="token function">vi</span> /etc/nginx/site-available/default server <span class="token punctuation">{</span> listen 80<span class="token punctuation">;</span> server_name your.domain<span class="token punctuation">;</span> location / <span class="token punctuation">{</span> proxy_pass http://127.0.0.1:8080<span class="token punctuation">;</span> proxy_set_header Host <span class="token variable">$host</span><span class="token punctuation">;</span> proxy_set_header X-Real-IP <span class="token variable">$remote_addr</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> nginx -s reload<span class="token function">vi</span> /etc/nginx/site-available/default server <span class="token punctuation">{</span> listen 80<span class="token punctuation">;</span> server_name your.domain<span class="token punctuation">;</span> location / <span class="token punctuation">{</span> proxy_pass http://127.0.0.1:8080<span class="token punctuation">;</span> proxy_set_header Host <span class="token variable">$host</span><span class="token punctuation">;</span> proxy_set_header X-Real-IP <span class="token variable">$remote_addr</span><span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span> nginx -s reloadvi /etc/nginx/site-available/default server { listen 80; server_name your.domain; location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } nginx -s reload
docker-compose updocker-compose updocker-compose up
查看浏览器是否能打开你挂载的网站
情况1.不可以打开
……各种排查错误
情况2.可以打开(假设可以打开)
docker-compose down docker-compose up -ddocker-compose down docker-compose up -ddocker-compose down docker-compose up -d
好的代码都需要测试,虽然我成功过一次,不过为了博客能好用些,我找了台相对干净的服务器来测试下
照着上面的步骤能否部署
我的docker早就装过了 2x版本的
出师不利 第一步遇到问题,新服务器没有更新 apt list
<span class="token function">apt-get</span> update<span class="token function">apt-get</span> updateapt-get update
安装完以后我发现没有弹出填写密码的提示
mysql mysql<span class="token operator">></span> <span class="token keyword">set</span> password <span class="token keyword">for</span> <span class="token string">'root'</span>@<span class="token string">'localhost'</span><span class="token operator">=</span>password<span class="token punctuation">(</span><span class="token string">'yourpassword'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> mysql<span class="token operator">></span> FLUSH PRIVILEGES<span class="token punctuation">;</span> mysql<span class="token operator">></span> <span class="token keyword">exit</span><span class="token punctuation">;</span>mysql mysql<span class="token operator">></span> <span class="token keyword">set</span> password <span class="token keyword">for</span> <span class="token string">'root'</span>@<span class="token string">'localhost'</span><span class="token operator">=</span>password<span class="token punctuation">(</span><span class="token string">'yourpassword'</span><span class="token punctuation">)</span><span class="token punctuation">;</span> mysql<span class="token operator">></span> FLUSH PRIVILEGES<span class="token punctuation">;</span> mysql<span class="token operator">></span> <span class="token keyword">exit</span><span class="token punctuation">;</span>mysql mysql> set password for 'root'@'localhost'=password('yourpassword'); mysql> FLUSH PRIVILEGES; mysql> exit;
nginx这块配置我就略过了
首次启动所以才开始拉镜像
第一次启动失败
我缺少个随机密码参数
environment: MYSQL_ROOT_PASSWOD: yourpassword MYSQL_RANDOM_ROOT_PASSWORD: <span class="token string">"1"</span>environment: MYSQL_ROOT_PASSWOD: yourpassword MYSQL_RANDOM_ROOT_PASSWORD: <span class="token string">"1"</span>environment: MYSQL_ROOT_PASSWOD: yourpassword MYSQL_RANDOM_ROOT_PASSWORD: "1"
第二次启动失败
没有连接权限
…经过了近两个半个小时的踩坑,终于部署成功
失败乃成功之母,把踩的坑也记录下来.问题主要是在连接不上数据库
这样的话wordpress就部署上去了。 本篇完
原文链接:https://jiuaidu.com/jianzhan/1066844/
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END