用Docker搭建WordPress

环境准备

  1. CentOS 安装docker

    https://yeasy.gitbooks.io/docker_practice/content/install/centos.html

  2. docker-compose安装

    https://yeasy.gitbooks.io/docker_practice/content/compose/install.html

  3. 创建目录
    mkdir -p /srv/docker/wordpress/wp-content

docker-compose

使用docker-compose组织wordpress和mysql,文件代码如下

version: "3"
services:

    wordpress:
     depends_on:
       - db
     image: wordpress:latest
     volumes:
      - /srv/docker/wordpress/wp-content:/var/www/html/wp-content
     ports:
       - "80:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: wordpress
       WORDPRESS_DB_PASSWORD: wordpress
     networks:
       - apinet
    db:
     image: mysql:5.7
     volumes:
       - db_data:/var/lib/mysql
     ports:
       - "3306:3306"
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: password
       MYSQL_DATABASE: wordpress
       MYSQL_USER: wordpress
       MYSQL_PASSWORD: wordpress
     networks:
       - apinet

networks:
    apinet:
volumes:
    db_data:

其中volumes 挂载本地存储,数据持久化,

启动

输入命令启动

docker-compose up -d
posted @ 2019-04-09 10:31  Just A Roamer!  阅读(263)  评论(0编辑  收藏  举报