|
| 1 | +# Docker Setup |
| 2 | + |
| 3 | +If you just want a ready to go docker environment you can just use the [quickstart](quickstart.md), do read on though if you're after more detail. |
| 4 | + |
| 5 | +### Pre-requisites |
| 6 | +#### Pre-requisites for Windows systems |
| 7 | +* [WSL](https://docs.microsoft.com/en-us/windows/wsl/install) |
| 8 | +* [Linux Kernel Update Package](https://docs.microsoft.com/en-gb/windows/wsl/install-manual#step-4---download-the-linux-kernel-update-package) |
| 9 | +* [Cygwin](https://cygwin.com/install.html) (be sure to include the gettext package on install) |
| 10 | +#### Pre-requisites for all systems |
| 11 | +* [Docker](https://www.docker.com/) |
| 12 | +* [Docker compose](https://docs.docker.com/compose/install/) |
| 13 | + |
| 14 | +### Env Vars |
| 15 | + |
| 16 | +You will also need to set up a bunch of environment variables |
| 17 | + |
| 18 | +#### .env |
| 19 | + |
| 20 | +Create a `.env` file based on `.env.dist`. |
| 21 | + |
| 22 | +On Linux systems you will want to set `USER_ID` and |
| 23 | +`GROUP_ID` to the uid/gid of your primary user. These |
| 24 | +do not need to be set on Windows/Mac systems. |
| 25 | + |
| 26 | +#### ./docker/database/.env |
| 27 | + |
| 28 | +Create the `.env` file baed on `.env.dist`. |
| 29 | + |
| 30 | +It is recommended to change the default passwords even |
| 31 | +for development environments. |
| 32 | + |
| 33 | +#### ./docker/app/.env |
| 34 | + |
| 35 | +Create the `.env` file based on `.env.dist`. |
| 36 | + |
| 37 | +It is recommended to change the default passwords even |
| 38 | +for development environments. |
| 39 | + |
| 40 | +> Env vars declared here will override any vars declared in the `.env` file in the root. See the header comment within the root `.env.dist` for an explanation as to why, baring in mind that in this context the 'real' environment is docker. |
| 41 | +
|
| 42 | +### Hosts file entries |
| 43 | + |
| 44 | +`127.0.0.1 $PROJECT_NAME.local` |
| 45 | + |
| 46 | +> If you want to change this you can, but you will need to make a change to `WP_HOME` in `./docker/app/.env`. |
| 47 | +
|
| 48 | +### Create environment |
| 49 | + |
| 50 | +* `docker network create --subnet=192.168.35.0/24 $DOCKER_NETWORK_NAME` |
| 51 | + |
| 52 | +> The docker network is required to ensure the loopback works with the expected IP address. |
| 53 | +
|
| 54 | +* `docker-compose build` |
| 55 | + |
| 56 | +> This only needs to be called once to build the image(s) |
| 57 | +
|
| 58 | +* Use `docker-compose up` to build the containers. You'll only need to use this the first time. |
| 59 | + |
| 60 | +* Use `docker-compose start` to start the container |
| 61 | + |
| 62 | +* Use `docker-compose stop` to stop the container (without removing the volumes). |
| 63 | + |
| 64 | +> Using docker-compose down stops containers but also removes them. This will lead to loss of data (e.g. your database). |
| 65 | +
|
| 66 | +That's it! You should now be able to browse to `https://$PROJECT_NAME.local` (or whatever you set) and view the site. Note, at time of writing you will need to go through the install script to have WordPress set up. |
| 67 | + |
| 68 | + |
| 69 | +### Running with Mac (And Docker Desktop) |
| 70 | + |
| 71 | +#### Xdebug |
| 72 | + |
| 73 | +We are running 2 app containers. By default, you will be using an xdebug-free container. |
| 74 | +This speeds up local env in browser and CLI as they no longer run xdebug for every request. |
| 75 | + |
| 76 | +**Setup** |
| 77 | + |
| 78 | + - Download a browser extension for your browser from https://www.jetbrains.com/help/phpstorm/2020.2/browser-debugging-extensions.html |
| 79 | + - Configure the browser extension to make sure the IDE key matches the one set in your `./docker/app/.env` (by default it is `wordpress`) |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + - Ensure your IDE is set up correctly. Screenshots below show PhpStorm setup as an example. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | + - To run xdebug in the browser: enable it in your IDE; add breakpoints; then go to your browser; enable xdebug in the browser extension (from first step of the setup) and reload the page. |
| 92 | + - To run xdebug in CLI: enable it in your IDE; add breakpoints; then execute the CLI command: |
| 93 | + |
| 94 | +``` |
| 95 | + docker-compose exec --user www-data app_xdebug php index.php |
| 96 | +``` |
| 97 | + |
| 98 | +Or, use one of the helper scripts located in `./bin/docker/xdebug` |
| 99 | + |
| 100 | +> On linux, remember to set `remote_host` to `192.168.35.1` |
| 101 | +
|
| 102 | +### Running composer or wp-cli |
| 103 | + |
| 104 | +If you wish to run composer or wp-cli there are two bin scripts that will allow you to run directly on the container: |
| 105 | + |
| 106 | +`bin/docker/composer` |
| 107 | +`bin/docker/wp` |
0 commit comments