exporting db using wpcli in docker

  docker, wordpress

I have created a wordpress website in localhost using docker. Everything works fine. Now I want to migrate the website to a live site,
I have use the command docker-compose run --rm cli bash to go into the shell and tried to use wp-cli to export the db. This is the command I used:

$ wp db export ~/wpdb-export-sp-date +%s.sql `

I got the following error:

mysqldump: Can't create/write to file '/home/www-data/sp.sql' (Errcode: 13 "Permission denied")

What should I do to export the file sucessfully?

I’m fairly new to docker, so where am I doing it wrong?

This is my docker-compose.yml file:


services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password 
    networks:
      - wpsite 
  # WordPress
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - '8000:80'
    restart: always
    volumes: 
      - ./:/var/www/html    
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - wpsite
  cli:
    image: wordpress:cli
    volumes:
      - ./:/var/www/html
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress   
    networks:
      - wpsite
networks:
  wpsite:
volumes:
  db_data: {} ```

Source: Docker Questions

LEAVE A COMMENT