docker搭建 mysql+phpadmin+wordpres

2019-05-15  本文已影响0人  _smoking_

环境

docker-compose.yml

建一个 docker-compose.yml文件

mysql
services:
    mysql:
        # 选中mariadb的最新版本
        image: mariadb:latest
        # 端口
        expose:
          - "3306"
        #映射本地 当前目录下mysql文件夹持久化
        volumes:
          - ./mysql:/var/lib/mysql
        #环境变量设置用户名密码
        environment:
          - MYSQL_ROOT_PASSWORD=123456
          - MYSQL_USER=wordpress
          - MYSQL_PASSWORD=123456
          - MYSQL_DATABASE=wordpress
          - MYSQL_RANDOM_ROOT_PASSWORD=1
        #挂掉自动重启
        restart: always
wordpress
wordpress:
    # 选中带有php-fpm 的版本,wordpress docker上有很多版本,根据自己情况选择需要的版本
    image: wordpress:5.2.0-php7.3-fpm
    # 把wordpress的主体文件夹映射到本地 wordpress目录
    volumes:
      - ./wordpress:/var/www/html
    # 环境变量 根据mysql 设置的填入
    environment:
      - WORDPRESS_DB_HOST=mysql
      - WORDPRESS_DB_NAME=wordpress
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=123456
    # 设置依赖
    depends_on:
      - mysql
    restart: always
phpmyadmin
phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    ports:
      - "8080:80"
    # 根据mysql设置相关环境变量
    environment:
        - PMA_HOST=mysql
        - PMA_USER=wordpress
        - PMA_PASSWORD=123456
    depends_on:
          - mysql
          - nginx
    restart: always
nginx
nginx:
    image: nginx:latest
    ports:
      - '80:80'
      - '443:443'
    # 映射本地,加载本地的配置
    volumes:
      - ./nginx:/etc/nginx/conf.d
      - ./logs/nginx:/var/log/nginx
      - ./wordpress:/var/www/html  #这里选择本地wordpress即 wordpress。docker中的目录
    depends_on:
      - wordpress
    restart: always

nginx配置

根据上面配置在当前目录下创建一个nginx文件夹,存放配置文件,配置如下

server {
listen 80;
server_name localhost;

    root /var/www/html;
    index index.php;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass wordpress:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

启动容器

​ 启动:docker-compose up

QA

如果wordpress 或者phpadmin 链接数据库失败,单独重启一下 wordpress 或者phpadmin 即可

待优化

github 地址


深圳利程电子有限公司

上一篇下一篇

猜你喜欢

热点阅读