So I decided to try Docker for my local Wordpress development.
Luckily, Docker has a quickstart guide for that.
I followed the entire process and I *think* I understood most of it. However, when I had the Docker container up and running, it made a clean installation of Wordpress instead of using the local files I had for a project. I initially thought that changing the directory to the project folder allowed it to read the files in it. Apparently, I was mistaken. I've tried searching the net for an answer and
most of them are just tutorials into how to use Docker for WP.
So with that in mind, how do I create a Docker container (or change the Docker YAML file) that uses the local WP files I have?
docker-compose.yml
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
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
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
Project structure
/project
/app
/sql
docker-compose.yml
I'm running on Ubuntu 19.04
Wordpress on docker
Create the docker-compose.yml with the follwing
version: '3.1'
services:
wordpress:
image: wordpress
restart: always
ports:
- 8080:80
volumes:
- ./app:/var/www/html
environment:
WORDPRESS_DB_PASSWORD: DoKRteST
WORDPRESS_DB_HOST: mysql
mysql:
image: mysql:5.7
# Uncomment the below code to maintain the persistancy of the data
# volumes:
# - ./wordpress:/var/www/html
restart: always
environment:
MYSQL_ROOT_PASSWORD: DoKRteST
./app folder is the actual wordpress app folder
Simply click on
to run it on Play with docker
You just need to mount wp-content of the host to the container. you can look for wp-content in your current directory structure probably under app/wp-content
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
volumes:
- wp-content:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
You can read more details here and here
Related
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.
I've created a docker yml file what contains the db and wordpress image and I want to connect Apache to Wordpress. How do I let Apache know the PHP files from Wordpress and how do I can connect to my webserver with my own url.
These are my docker containers which are running
https://i.stack.imgur.com/5Wi1F.png
Is this way right?
I edit this cfg "wp-config.php" for my example url:
define('WP_HOME', 'http://www.example.com/');
define('WP_SITEURL', 'http://www.example.com/'); `
But I can't connect it.
#czende
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
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8080:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
I downloaded a github folder with a wordpress site, after the unzip the weight of it is about 1,8 gb.
Inside the master folder I've 9 folders, two of them named:
1: wp-content
2: wp-includes
I already created the docker-compose.yml file and the code inside it is 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
wordpress:
depends_on:
- db
image: wordpress:5.1.1-php7.3-apache
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
volumes:
db_data:
The lines up above are necessary only for install wordpress.
Now my question is, what could I do to install and launch the complete site that i downloaded ?
The entire process must be done with docker, install and launch the site.
Thank you for everything :)
Ensure you have the volume mount points which contains the existing app source code and the db files and the script to do db update.
wordpress section in docker-compose
volumes:
- ./codeblog.dotsandbrackets.com:/var/www/html
mysql section in docker-compose
volumes:
- ./codeblog.dotsandbrackets.com.20170808-024302.sql.gz:/docker-entrypoint-initdb.d/backup.sql.gz
- ./migrate.sql:/docker-entrypoint-initdb.d/migrate.sql
This example uses nginx webserver
Ref : https://codeblog.dotsandbrackets.com/migrate-wordpress-docker/
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:
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: