Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volume mount when setting up Wordpress with docker

Quickstart: Compose and WordPress proposes the following docker-compose.yml

version: '3.3'  services:    db:      image: mysql:5.7      volumes:        - dbdata:/var/lib/mysql      restart: always      environment:        MYSQL_ROOT_PASSWORD: somewordpress        MYSQL_DATABASE: wordpress        MYSQL_USER: wordpress        MYSQL_PASSWORD: wordpress     wordpress:      depends_on:        - db      image: wordpress:latest      ports:        - "8000:80"      restart: always      environment:        WORDPRESS_DB_HOST: db:3306        WORDPRESS_DB_USER: wordpress        WORDPRESS_DB_PASSWORD: wordpress volumes:     dbdata: 

For persisting database data, a volume is created:

  • The docker volume db_data persists any updates made by Wordpress to the database.

but nothing is mentioned about the wordpress container...

Questions:

  1. should I follow the same approach and create volumes for the wordpress container, in order to persist the data that are going to be added (by posts, uploads, themes)?
  2. If yes, which paths / directories should I point to?
like image 807
tgogos Avatar asked Mar 09 '18 21:03

tgogos


People also ask

Can you mount a volume while building your Docker image?

When building an image, you can't mount a volume. However, you can copy data from another image! By combining this, with a multi-stage build, you can pre-compute an expensive operation once, and re-use the resulting state as a starting point for future iterations.

Can you run WordPress in Docker?

You can use Docker Compose to easily run WordPress in an isolated environment built with Docker containers. This quick-start guide demonstrates how to use Compose to set up and run WordPress. Before starting, make sure you have Compose installed.


1 Answers

Maybe I've found something...

volumes:    - wp-content:/var/www/html/wp-content 

According to this article:

...wp-content contains all user-supplied content. Basically anything you can upload to your site ends up here. That doesn’t include anything you write, mind you. Those things are stored in the WordPress database.

However, as long as you have both the database and your wp-content folder, you can always get your site back, even if everything else was lost.

This is also applied here: Setting up WordPress with Docker


To try it out:

version: '3.3'  services:   db:    image: mysql:5.7    volumes:      - dbdata:/var/lib/mysql    restart: always    environment:      MYSQL_ROOT_PASSWORD: somewordpress      MYSQL_DATABASE: wordpress      MYSQL_USER: wordpress      MYSQL_PASSWORD: wordpress    wordpress:    depends_on:      - db    image: wordpress:latest    volumes:      - wp-content:/var/www/html/wp-content    ports:      - "8000:80"    restart: always    environment:      WORDPRESS_DB_HOST: db:3306      WORDPRESS_DB_USER: wordpress      WORDPRESS_DB_PASSWORD: wordpress  volumes:   dbdata:   wp-content: 
like image 138
tgogos Avatar answered Sep 20 '22 22:09

tgogos