一、编写dockerfile
<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> FROM centos:7 RUN <span class="token function">curl</span> -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo RUN yum <span class="token function">install</span> nginx mariadb-server php-fpm php-mysql -y RUN mysql_install_db --user<span class="token operator">=</span>mysql --defaults-file<span class="token operator">=</span>/etc/my.cnf RUN tmp<span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">nohup</span> mysqld_safe --defaults-file<span class="token operator">=</span>/etc/my.cnf <span class="token operator">&</span><span class="token variable">`</span></span> <span class="token operator">&&</span> <span class="token function">sleep</span> 5 <span class="token operator">&&</span> \ mysql -e <span class="token string">"create database wordpress;"</span> <span class="token operator">&&</span> \ mysql -e <span class="token string">"grant all on wordpress.* to wordpress@localhost identified by '123456';"</span> ADD www.conf /etc/php-fpm.d/www.conf ADD nginx.conf /etc/nginx/nginx.conf RUN <span class="token function">mkdir</span> /code WORKDIR /code ADD wordpress-4.9.4.zip <span class="token keyword">.</span> RUN yum <span class="token function">install</span> unzip -y RUN unzip wordpress-4.9.4.zip RUN <span class="token function">mv</span> wordpress/* <span class="token keyword">.</span> RUN <span class="token function">chown</span> -R nginx:nginx <span class="token keyword">.</span> ADD init.sh /init.sh CMD <span class="token punctuation">[</span><span class="token string">"/bin/bash"</span>,<span class="token string">"/init.sh"</span><span class="token punctuation">]</span><span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> FROM centos:7 RUN <span class="token function">curl</span> -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo RUN yum <span class="token function">install</span> nginx mariadb-server php-fpm php-mysql -y RUN mysql_install_db --user<span class="token operator">=</span>mysql --defaults-file<span class="token operator">=</span>/etc/my.cnf RUN tmp<span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">nohup</span> mysqld_safe --defaults-file<span class="token operator">=</span>/etc/my.cnf <span class="token operator">&</span><span class="token variable">`</span></span> <span class="token operator">&&</span> <span class="token function">sleep</span> 5 <span class="token operator">&&</span> \ mysql -e <span class="token string">"create database wordpress;"</span> <span class="token operator">&&</span> \ mysql -e <span class="token string">"grant all on wordpress.* to wordpress@localhost identified by '123456';"</span> ADD www.conf /etc/php-fpm.d/www.conf ADD nginx.conf /etc/nginx/nginx.conf RUN <span class="token function">mkdir</span> /code WORKDIR /code ADD wordpress-4.9.4.zip <span class="token keyword">.</span> RUN yum <span class="token function">install</span> unzip -y RUN unzip wordpress-4.9.4.zip RUN <span class="token function">mv</span> wordpress/* <span class="token keyword">.</span> RUN <span class="token function">chown</span> -R nginx:nginx <span class="token keyword">.</span> ADD init.sh /init.sh CMD <span class="token punctuation">[</span><span class="token string">"/bin/bash"</span>,<span class="token string">"/init.sh"</span><span class="token punctuation">]</span>[root@docker01 wordpress] FROM centos:7 RUN curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo RUN yum install nginx mariadb-server php-fpm php-mysql -y RUN mysql_install_db --user=mysql --defaults-file=/etc/my.cnf RUN tmp=`nohup mysqld_safe --defaults-file=/etc/my.cnf &` && sleep 5 && \ mysql -e "create database wordpress;" && \ mysql -e "grant all on wordpress.* to wordpress@localhost identified by '123456';" ADD www.conf /etc/php-fpm.d/www.conf ADD nginx.conf /etc/nginx/nginx.conf RUN mkdir /code WORKDIR /code ADD wordpress-4.9.4.zip . RUN yum install unzip -y RUN unzip wordpress-4.9.4.zip RUN mv wordpress/* . RUN chown -R nginx:nginx . ADD init.sh /init.sh CMD ["/bin/bash","/init.sh"]
二、准备nginx配置文件
server <span class="token punctuation">{<!-- --></span> listen 80<span class="token punctuation">;</span> server_name localhost<span class="token punctuation">;</span> root /code<span class="token punctuation">;</span> location / <span class="token punctuation">{<!-- --></span> index index.php index.html index.htm<span class="token punctuation">;</span> <span class="token punctuation">}</span> location ~ \.php$ <span class="token punctuation">{<!-- --></span> fastcgi_pass 127.0.0.1:9000<span class="token punctuation">;</span> fastcgi_param SCRIPT_FILENAME <span class="token variable">$document_root</span><span class="token variable">$fastcgi_script_name</span><span class="token punctuation">;</span> include fastcgi_params<span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span>server <span class="token punctuation">{<!-- --></span> listen 80<span class="token punctuation">;</span> server_name localhost<span class="token punctuation">;</span> root /code<span class="token punctuation">;</span> location / <span class="token punctuation">{<!-- --></span> index index.php index.html index.htm<span class="token punctuation">;</span> <span class="token punctuation">}</span> location ~ \.php$ <span class="token punctuation">{<!-- --></span> fastcgi_pass 127.0.0.1:9000<span class="token punctuation">;</span> fastcgi_param SCRIPT_FILENAME <span class="token variable">$document_root</span><span class="token variable">$fastcgi_script_name</span><span class="token punctuation">;</span> include fastcgi_params<span class="token punctuation">;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span>server { listen 80; server_name localhost; root /code; location / { index index.php index.html index.htm; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
三、修改/etc/php-fpm.d/www.conf
<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> user <span class="token operator">=</span> nginx group <span class="token operator">=</span> nginx<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> user <span class="token operator">=</span> nginx group <span class="token operator">=</span> nginx[root@docker01 wordpress] user = nginx group = nginx
四、准备wordpress软件包,5以上版本不支持
<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> -rw------- 1 root root 9332728 May 29 20:50 wordpress-4.9.4.zip<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> -rw------- 1 root root 9332728 May 29 20:50 wordpress-4.9.4.zip[root@docker01 wordpress] -rw------- 1 root root 9332728 May 29 20:50 wordpress-4.9.4.zip
五、编写初始化脚本,数据库后台启动
<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> nginx php-fpm -D mysqld_safe --defaults-file<span class="token operator">=</span>/etc/my.cnf<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> nginx php-fpm -D mysqld_safe --defaults-file<span class="token operator">=</span>/etc/my.cnf[root@docker01 wordpress] nginx php-fpm -D mysqld_safe --defaults-file=/etc/my.cnf
六、运行dockerfile
<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span><span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span>[root@docker01 wordpress]
七、启动容器
<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> 92267d753afa195d268fe67cedafe5203e2b74b0e525c99962577ea6c7a3f758<span class="token punctuation">[</span>root@docker01 wordpress<span class="token punctuation">]</span> 92267d753afa195d268fe67cedafe5203e2b74b0e525c99962577ea6c7a3f758[root@docker01 wordpress] 92267d753afa195d268fe67cedafe5203e2b74b0e525c99962577ea6c7a3f758
八、查看网页
原文链接:https://blog.csdn.net/octtom/article/details/106432935
© 版权声明
声明📢本站内容均来自互联网,归原创作者所有,如有侵权必删除。
本站文章皆由CC-4.0协议发布,如无来源则为原创,转载请注明出处。
THE END