panay
panay

Reputation: 90

How to mount wordpress files into exists directory?

everyone!

The problem is as follows:

I have the docker-compose.yml file which contains settings for nginx, nuxt, wordpress and mysql. I can't mount wordpress files from image to local directory.

What am I doing wrong?

docker-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:

Dockerfile for the wordpress:

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"]

Upvotes: 1

Views: 1527

Answers (2)

Jinna Baalu
Jinna Baalu

Reputation: 7839

Docker compose file for wordpress

First clean up the old folders and create a new folder or delete the mounted volumes, like db, wp folder, then re run the app

To start from scratch follow this steps

docker-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

Create nginx folder

Add the following file to the nginx folder

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

Now you will see the content in html folder where you can see the code related to the wordpress.

Upvotes: 1

mahes wari
mahes wari

Reputation: 91

Try to give the absolute path in volume [e.g /home/user/wp] and check whether "wp" folder has been created.

Upvotes: 2

Related Questions