Add service for wp cli, extend docs, add license, close #11

This commit is contained in:
Harald Nezbeda
2018-10-01 23:29:22 +02:00
parent 5014cf3955
commit b64ed4a431
4 changed files with 73 additions and 20 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2018 nezhar
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+34 -10
View File
@@ -5,15 +5,17 @@
## Starting a new project
Make sure you have the latest versions of **Docker** and **Docker Compose** installed on your machine.
Copy the **docker-compose.yml** file from this repository into a blank folder.
Copy the files from this repository into a blank folder. In the **docker-compose.yml** file you may change the IP address (in case you run multiple containers) or the database from mysql to mariadb.
Make sure to add your user to the docker group when using linux:
https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user
In the file you may change the IP address (in case you run multiple containers) or the database from mysql to mariadb.
##### Create containers
Open a terminal and *cd* to the folder you have the docker-compose.yml and run:
```
sudo docker-compose up
docker-compose up
```
This create 2 new folders beside your docker-compose.yml file.
@@ -26,23 +28,23 @@ The containers are now build and running. You should be able to access the Wordp
You can start the containers with the up command in daemon mode (by adding **-d** as a param) or by using the start command:
```
sudo docker-compose start
docker-compose start
```
##### Stopping containers
```
sudo docker-compose stop
docker-compose stop
```
##### Remove containers
To stop and remove all the containers use the **down** command
```
sudo docker-compose down
docker-compose down
```
... or the **rm** command if the containers are stopped already.
Use **-v** if you need to remove the database volume which is used to persist the database:
```
sudo docker-compose rm
docker-compose down -v
```
## Project from existing source
@@ -53,7 +55,7 @@ Copy the docker-compose.yml file into a new directory. In the directory you crea
You can now use the **up** command:
```
sudo docker-compose up
docker-compose up
```
This will create the containers and populate the database with the given dump. You may set your host entry and change it in the database, or you simply overwrite it in the **wp-config.php** by adding
@@ -64,7 +66,7 @@ define('WP_SITEURL','http://wp-app.local');
## Creating database dumps
```
sudo ./export.sh
./export.sh
```
---
@@ -85,3 +87,25 @@ Configure the volume to load the plugin in the container in the docker-compose.y
volumes:
- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name
```
## WP CLI
The docker compose configuration also provides a service for using the [Wordpress CLI](https://developer.wordpress.org/cli/commands/).
Sample command:
```
docker-compose run --rm wpcli plugin list
```
For an easier usage you may consider adding an alias for the CLI:
```
alias wp="docker-compose run --rm wpcli"
```
This way you can use the CLI command above as follows:
```
wp plugin list
```
+17 -9
View File
@@ -1,6 +1,7 @@
version: '2'
version: '3'
services:
wordpress:
wp:
image: wordpress:latest # https://hub.docker.com/_/wordpress/
ports:
- 127.0.0.1:80:80 # change ip if required
@@ -16,8 +17,16 @@ services:
WORDPRESS_DB_PASSWORD: password
depends_on:
- db
networks:
- wordpress-network
wpcli:
image: wordpress:cli
user: xfs
volumes:
- ./wp-app:/var/www/html
depends_on:
- db
- wp
db:
image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb
ports:
@@ -29,11 +38,10 @@ services:
]
volumes:
- ./wp-data:/docker-entrypoint-initdb.d
- db_data:/var/lib/mysql
environment:
MYSQL_DATABASE: wordpress
MYSQL_ROOT_PASSWORD: password
networks:
- wordpress-network
networks:
wordpress-network:
driver: bridge
volumes:
db_data:
+1 -1
View File
@@ -2,7 +2,7 @@
_os="`uname`"
_now=$(date +"%m_%d_%Y")
_file="wp-data/data_$_now.sql"
docker-compose exec db sh -c 'exec mysqldump "$MYSQL_DATABASE" -uroot -p"$MYSQL_ROOT_PASSWORD"' > $_file
docker-compose run --rm db sh -c 'exec mysqldump "$MYSQL_DATABASE" -uroot -p"$MYSQL_ROOT_PASSWORD"' > $_file
if [[ $_os == "Darwin"* ]] ; then
sed -i '.bak' 1,1d $_file
else