├── .gitignore ├── .github └── FUNDING.yml ├── env.example ├── config ├── pma_config.php ├── wp_php.ini └── pma_php.ini ├── export.sh ├── LICENSE ├── docker-compose.yml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: nezhar 2 | -------------------------------------------------------------------------------- /env.example: -------------------------------------------------------------------------------- 1 | IP=127.0.0.1 2 | PORT=80 3 | DB_ROOT_PASSWORD=password 4 | DB_NAME=wordpress 5 | -------------------------------------------------------------------------------- /config/pma_config.php: -------------------------------------------------------------------------------- 1 | $_file 9 | 10 | if [[ $_os == "Darwin"* ]] ; then 11 | sed -i '.bak' 1,1d $_file 12 | else 13 | sed -i 1,1d $_file # Removes the password warning from the file 14 | fi 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2018 nezhar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | 3 | services: 4 | wp: 5 | image: wordpress:latest # https://hub.docker.com/_/wordpress/ 6 | ports: 7 | - ${IP}:${PORT}:80 # change ip if required 8 | volumes: 9 | - ./config/wp_php.ini:/usr/local/etc/php/conf.d/conf.ini 10 | - ./wp-app:/var/www/html # Full wordpress project 11 | #- ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name # Plugin development 12 | #- ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name # Theme development 13 | environment: 14 | WORDPRESS_DB_HOST: db 15 | WORDPRESS_DB_NAME: "${DB_NAME}" 16 | WORDPRESS_DB_USER: root 17 | WORDPRESS_DB_PASSWORD: "${DB_ROOT_PASSWORD}" 18 | depends_on: 19 | - db 20 | links: 21 | - db 22 | 23 | wpcli: 24 | image: wordpress:cli 25 | volumes: 26 | - ./config/wp_php.ini:/usr/local/etc/php/conf.d/conf.ini 27 | - ./wp-app:/var/www/html 28 | environment: 29 | WORDPRESS_DB_HOST: db 30 | WORDPRESS_DB_NAME: "${DB_NAME}" 31 | WORDPRESS_DB_USER: root 32 | WORDPRESS_DB_PASSWORD: "${DB_ROOT_PASSWORD}" 33 | depends_on: 34 | - db 35 | - wp 36 | 37 | pma: 38 | image: phpmyadmin:latest # https://hub.docker.com/_/phpmyadmin 39 | environment: 40 | # https://docs.phpmyadmin.net/en/latest/setup.html#docker-environment-variables 41 | PMA_HOST: db 42 | PMA_PORT: 3306 43 | MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}" 44 | UPLOAD_LIMIT: 50M 45 | ports: 46 | - ${IP}:8080:80 47 | links: 48 | - db:db 49 | volumes: 50 | - ./config/pma_php.ini:/usr/local/etc/php/conf.d/conf.ini 51 | - ./config/pma_config.php:/etc/phpmyadmin/config.user.inc.php 52 | 53 | db: 54 | image: mysql:latest # https://hub.docker.com/_/mysql/ - or mariadb https://hub.docker.com/_/mariadb 55 | # platform: linux/x86_64 # Uncomment if your machine is running on arm (ex: Apple Silicon processor) 56 | ports: 57 | - ${IP}:3306:3306 # change ip if required 58 | command: [ 59 | '--character-set-server=utf8mb4', 60 | '--collation-server=utf8mb4_unicode_ci' 61 | ] 62 | volumes: 63 | - ./wp-data:/docker-entrypoint-initdb.d 64 | - db_data:/var/lib/mysql 65 | environment: 66 | MYSQL_DATABASE: "${DB_NAME}" 67 | MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}" 68 | 69 | volumes: 70 | db_data: 71 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WPDC - WordPress Docker Compose 2 | 3 | Easy WordPress development with Docker and Docker Compose. 4 | 5 | With this project you can quickly run the following: 6 | 7 | - [WordPress and WP CLI](https://hub.docker.com/_/wordpress/) 8 | - [phpMyAdmin](https://hub.docker.com/r/phpmyadmin/phpmyadmin/) 9 | - [MySQL](https://hub.docker.com/_/mysql/) 10 | 11 | Contents: 12 | 13 | - [Requirements](#requirements) 14 | - [Configuration](#configuration) 15 | - [Installation](#installation) 16 | - [Usage](#usage) 17 | 18 | ## Requirements 19 | 20 | Make sure you have the latest versions of **Docker** and **Docker Compose** installed on your machine. 21 | 22 | Clone this repository or copy the files from this repository into a new 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. 23 | 24 | Make sure to [add your user to the `docker` group](https://docs.docker.com/install/linux/linux-postinstall/#manage-docker-as-a-non-root-user) when using Linux. 25 | 26 | ## Configuration 27 | 28 | Copy the example environment into `.env` 29 | 30 | ``` 31 | cp env.example .env 32 | ``` 33 | 34 | Edit the `.env` file to change the default IP address, MySQL root password and WordPress database name. 35 | 36 | ## Installation 37 | 38 | Open a terminal and `cd` to the folder in which `docker-compose.yml` is saved and run: 39 | 40 | ``` 41 | docker-compose up 42 | ``` 43 | 44 | This creates two new folders next to your `docker-compose.yml` file. 45 | 46 | * `wp-data` – used to store and restore database dumps 47 | * `wp-app` – the location of your WordPress application 48 | 49 | The containers are now built and running. You should be able to access the WordPress installation with the configured IP in the browser address. By default it is `http://127.0.0.1`. 50 | 51 | For convenience you may add a new entry into your hosts file. 52 | 53 | ## Usage 54 | 55 | ### Starting containers 56 | 57 | You can start the containers with the `up` command in daemon mode (by adding `-d` as an argument) or by using the `start` command: 58 | 59 | ``` 60 | docker-compose start 61 | ``` 62 | 63 | ### Stopping containers 64 | 65 | ``` 66 | docker-compose stop 67 | ``` 68 | 69 | ### Removing containers 70 | 71 | To stop and remove all the containers use the`down` command: 72 | 73 | ``` 74 | docker-compose down 75 | ``` 76 | 77 | Use `-v` if you need to remove the database volume which is used to persist the database: 78 | 79 | ``` 80 | docker-compose down -v 81 | ``` 82 | 83 | ### Project from existing source 84 | 85 | Copy the `docker-compose.yml` file into a new directory. In the directory you create two folders: 86 | 87 | * `wp-data` – here you add the database dump 88 | * `wp-app` – here you copy your existing WordPress code 89 | 90 | You can now use the `up` command: 91 | 92 | ``` 93 | docker-compose up 94 | ``` 95 | 96 | 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 `wp-config.php` by adding: 97 | 98 | ``` 99 | define('WP_HOME','http://wp-app.local'); 100 | define('WP_SITEURL','http://wp-app.local'); 101 | ``` 102 | 103 | ### Creating database dumps 104 | 105 | ``` 106 | ./export.sh 107 | ``` 108 | 109 | ### Developing a Theme 110 | 111 | Configure the volume to load the theme in the container in the `docker-compose.yml`: 112 | 113 | ``` 114 | volumes: 115 | - ./theme-name/trunk/:/var/www/html/wp-content/themes/theme-name 116 | ``` 117 | 118 | ### Developing a Plugin 119 | 120 | Configure the volume to load the plugin in the container in the `docker-compose.yml`: 121 | 122 | ``` 123 | volumes: 124 | - ./plugin-name/trunk/:/var/www/html/wp-content/plugins/plugin-name 125 | ``` 126 | 127 | ### WP CLI 128 | 129 | The docker compose configuration also provides a service for using the [WordPress CLI](https://developer.wordpress.org/cli/commands/). 130 | 131 | Sample command to install WordPress: 132 | 133 | ``` 134 | docker-compose run --rm wpcli core install --url=http://localhost --title=test --admin_user=admin --admin_email=test@example.com 135 | ``` 136 | 137 | Or to list installed plugins: 138 | 139 | ``` 140 | docker-compose run --rm wpcli plugin list 141 | ``` 142 | 143 | For an easier usage you may consider adding an alias for the CLI: 144 | 145 | ``` 146 | alias wp="docker-compose run --rm wpcli" 147 | ``` 148 | 149 | This way you can use the CLI command above as follows: 150 | 151 | ``` 152 | wp plugin list 153 | ``` 154 | 155 | ### phpMyAdmin 156 | 157 | You can also visit `http://127.0.0.1:8080` to access phpMyAdmin after starting the containers. 158 | 159 | The default username is `root`, and the password is the same as supplied in the `.env` file. 160 | --------------------------------------------------------------------------------