0%

基于centos搭建wordpress的docker镜像


作者: 耗子007


自定义的Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
FROM centos

ENV http_proxy http://username:password@proxy:8080
ENV https_proxy http://username:password@proxy:8080

#RUN echo “http_proxy=http://username:password@proxy:8080” >> /etc/apt/apt.conf
#RUN echo “https_proxy=http://username:password@proxy:8080” >> /etc/apt/apt.conf

RUN touch /etc/wgetrc
RUN echo “http_proxy=http://username:password@proxy:8080” >> /etc/wgetrc
RUN echo “https_proxy=http://username:password@proxy:8080” >> /etc/wgetrc
RUN source /etc/wgetrc

RUN yum -y update
RUN yum -y install httpd httpd-devel zip unzip tar wget
RUN yum -y install php php-xml php-pdo php-gd php-mbstring sqlite sqlite-devel

RUN wget –no-check-certificate https://wordpress.org/latest.tar.gz(中文版链接:https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz)
RUN wget –no-check-certificate https://downloads.wordpress.org/plugin/sqlite-integration.1.8.1.zip
RUN tar xvfz ./latest.tar.gz
RUN unzip ./sqlite-integration.1.8.1.zip
RUN rm -f ./latest.tar.gz
RUN rm -f ./sqlite-integration.1.8.1.zip
RUN mv wordpress /var/lib/wordpress
RUN chown -R apache.apache /var/lib/wordpress
RUN mv /var/lib/wordpress/wp-config-sample.php /var/lib/wordpress/wp-config.php
RUN mv sqlite-integration /var/lib/wordpress/wp-content/plugins/
RUN mv /var/lib/wordpress/wp-content/plugins/sqlite-integration/db.php \
/var/lib/wordpress/wp-content/

RUN echo “yes n | cp -ripf /var/lib/wordpress/* /var/www/html/ > /dev/null 2>&1” >> /root/.bash_profile
VOLUME /var/www/html

RUN systemctl enable httpd

EXPOSE 80

#docker run –privileged -itd -p 8080:80 -v /root/wordpress/public_html:/var/www/html wordpress_sqlite bash -l -c “/sbin/init”

然后构建docker镜像,执行命令:docker build –tag wordpress_sqlite .

现在新建wordpress的在host上的文件目录,如:/home/rtos/workspace/wordpress/public_html/

启动wordpress服务,执行如下命令:

1
2
3
docker run –privileged -itd -p 8080:80 -v /home/rtos/workspace/wordpress/public_html/:/var/www/html wordpress_sqlite bash -l -c “sbin/init”

等待几分钟,访问http://localhost:8080,或者http://ip:8080

注意:

  • 我们的博客数据是放到SQLite数据库 (/var/www/html/wp-content/database/.ht.sqlite文件)
  • 而网站的所有程序是放到(目录/var/www/html)
  • 关于如何备份数据以及迁移博客,后续分析。