Volume mount when setting up Wordpress with docker - wordpress

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:
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)?
If yes, which paths / directories should I point to?

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:

Related

Wordpress on docker compose doesn't load css

I'm new to docker and databases but my first project on local host doesn't load as expected. The side appears but the content is scattered. Here is the .yml file
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/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:
- ./www:/var/www/html
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
Every time you run
$ docker-compose up
Docker create a new network to which all the containers in your compose file will be connected to.
In the first run of this compose file, you do the installation of Wordpress,
and Wordpress insert the IP address of your web site in the database.
The problem occur when you stop this compose file with:
$ docker-compose down
the network created with "docker-compose up" is removed
and when you run the compose file again, docker will create a new network with different IP addresses, so links become broken because your webpages still point to the old IP address.
A solution can be to create a network outside compose file with:
$ docker network create my_network
and empty the volume "dbdata" and the folder "./www" (and lose all your data) then update your compose file with:
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/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:
- ./www:/var/www/html
ports:
- "80:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
networks:
default:
external:
name: my_network
I think there is solution to this problem without losing your data, for more information you can read this article.

Connecting to my local docker Database Instance from Table Plus

I have created a local docker wordpress instance and I am trying to connect to the database with a SQL Client (in my case TablePlus) but I am having trouble.
I created the docker containers from a docker-compose.yml file shown here:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/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:
- "8028:80"
- "8029:8029"
volumes:
- ./themes/travelmatic:/var/www/html/wp-content/themes/yadayada
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
VIRTUAL_HOST: leasepilot.local
volumes:
db_data:
I have tried any comibindation of wordpress and somewordpress in these fields:
I also have the option to connect over SSH but I don't feel I would need to do that?
1) What is the best way to debug this type of issue?
2) What are the creds? lol
There is another bit of information that should be added to the Praveen answer.
If you have already mysql installed locally, on your computer/laptop, settings the db ports to:
- "3306:3306"
it won't work because TablePlus will connect to your local mysql instance.
Instead you should set your Docker mysql on a different published port and access that from TablePlus.
For example, set these ports on your Dockerfile (published port is 3356):
"3356:3306"
Then set the same port on TablePlus:
Just as David has suggested in his comment, you need to add port mapping in docker-compose.yml. So, your modified docker-compose.yml would be something like this:
version: '3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
ports:
- "3306:3306"
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8028:80"
- "8029:8029"
volumes:
- ./themes/travelmatic:/var/www/html/wp-content/themes/yadayada
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
VIRTUAL_HOST: leasepilot.local
volumes:
db_data:
And you have already provided the creds in the docker-compose.yml in environment variables.

How to access wordpress-docker site on another computer in network

I created WordPress website and configure it within the Docker. The site displays all it's contains locally correctly. Now I want to access that website from the another machine within same network but it did not display all the contents correctly. it displays only the text. no images and the applied theme is not displays. I think problem is WORDPRESS_DB_HOST: db:3306 but how to change that. I access my site locally at http://localhost:8000/
version: '2'
services:
wordpress:
depends_on:
- db
image: wordpress:latest
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
ports:
- 8000:80
- 4443:443
networks:
- back
db:
image: mysql:5.7
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
networks:
- back
phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 8001:80
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: somewordpress
networks:
- back
networks:
back:
volumes:
db_data:
From another system in the same network, you can call the WordPress website using the IP of the System where your docker container is running.
For Example, Let say you are running the WordPress Container in System A.
Find the System IP of A It will be like 192.168.0.10
Then from System B Call 192.168.0.10:8000 This will work for you.

Docker Compose Wordpress Persistant Plugin Install

How do I make it such that I can upload plugins and have them persist on docker compose setup? I'm working with wordpress 4. My docker compose is for a plugin I'm developing, and I would like to have it automatically install my plugins. Right now I'm trying to use volumes to fudge it, and persist them, but the directory is not writable.
Or is there a way to say add these plugins on setup with the default wordpress image?
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
ports:
- "3306:3306"
wordpress:
depends_on:
- db
image: wordpress:4.9-php7.2-apache
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
- ".:/var/www/html/wp-content/plugins/xxx:ro"
- plugins:/var/www/html/wp-content/:Z
volumes:
db_data:
plugins:

MacOS - In file './docker-compose.yml', volume must be a mapping, not an array

I've seen responses for similar errors, but nothing that seems to address a solution that will work for me.
I've got a wordpress site that I've imported into docker following this tutorial. I've got everything down to the final part where I'm supposed to "docker compose up" and I'm getting the error listed in the subject line. Here is my .yml file:
version: "2"
services:
db:
image: mysql:5.6
volumes:
- db_data:/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:
- ./public_html/wp-content/themes/oceanwp:/var/www/html/wp-content/themes/oceanwp
- ./public_html/wp-content/plugins:/var/www/html/wp-content/plugins
- ./public_html/wp-content/mu-plugins:/var/www/html/wp-content/mu-plugins
volumes:
- ./data:/docker-entrypoint-initdb.d
I was wondering why your yml file is different from the one in the post.
I use the yml file in the post and it does work.
Remember that you can’t map a top-level volume in docker-compose , so blow is illegal, see link and link for more help.
volumes:
- ./data:/docker-entrypoint-initdb.d

Resources