如何将wordpress文件挂载到exists目录?

时间:2018-06-05 06:12:47

标签: wordpress docker docker-compose

大家好!

问题如下:

我有docker-compose.yml文件,其中包含nginx,nuxt,wordpress和mysql的设置。 我无法将wordpress文件从image安装到本地目录。

我做错了什么?

搬运工-compose.yml

version: '3'
services:
  nginx:
    image: nginx:alpine
    ports:
      - "80:80"
    depends_on:
      - nuxt
      - wp
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
      - ./logs/nginx:/var/log/nginx
    networks:
      - flat-network
  nuxt:
    build: ./nuxt
    depends_on:
      - wp
      - db
    environment:
      HOST: "0.0.0.0"
    volumes:
      - ./nuxt:/myapp
    networks:
      - flat-network
  wp:
    build: ./wp
    depends_on:
      - db
    environment:
      WORDPRESS_DB_HOST: "db:3306"
    env_file: .env
    volumes:
      - ./wp:/var/www/html
    networks:
      - flat-network
  db:
    build: mysql
    env_file: .env
    ports:
      - '3306:3306'
    networks:
      - flat-network

  networks:
    flat-network:

wordpress的Dockerfile:

FROM wordpress:php7.2-fpm-alpine

COPY cmd.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/cmd.sh
ENTRYPOINT ["cmd.sh"]
CMD ["cmd.sh"]

2 个答案:

答案 0 :(得分:1)

尝试在卷中提供绝对路径[例如/ home / user / wp]并检查是否已创建“wp”文件夹。

答案 1 :(得分:0)

Docker撰写wordpress文件

首先清理旧文件夹并创建新文件夹或删除已安装的卷,如db,wp文件夹,然后重新运行应用程序

要从头开始,请按照以下步骤操作

<强>搬运工-compose.yml

version: '2'

services:
  nginx:
    image: nginx:latest
    ports:
        - '80:80'
    volumes:
        - ./nginx:/etc/nginx/conf.d
        - ./html:/var/www/html
    links:
        - wordpress
    restart: always

  mysql:
    image: mariadb
    ports:
        - '3306:3306'
    volumes:
        - /var/db/mysql_backup_folder3/test/mysql:/var/lib/mysql
    environment:
        - MYSQL_USER=test
        - MYSQL_ROOT_PASSWORD=TestDb123
        - MYSQL_DATABASE=testdb
        - MYSQL_PASSWORD=TestDb123
    restart: always

  wordpress:
    image: wordpress:4.7.1-php7.0-fpm
    ports:
        - '9000:9000'
    volumes:
        - ./html:/var/www/html
    environment:
        - WORDPRESS_DB_NAME=testdb
        - WORDPRESS_DB_USER=test
        - WORDPRESS_DB_HOST=mysql
        - WORDPRESS_DB_PASSWORD=TestDb123
    links:
        - mysql
    restart: always

创建nginx文件夹

将以下文件添加到nginx文件夹

<强> wordpress.conf

server {
     listen 80;
     server_name example.com;

     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;
     }
 }

RUN

  

docker-compose up -d

现在,您将看到html文件夹中的内容,您可以在其中看到与wordpress相关的代码。