If you work with different docker environments at the same time you need to manage the ports. wp-env uses port 8888 by default. If this port is already in use by another project then you have a problem.
The solution is basically quite simple: Just change the ports. Admittedly this is quite annoying to check every time which ports are occupied and to configure a free port in a extra configuration file.
Therefore, I simply wrote a small npm package that accomplishes this task: wp-env-port-stamp generates every time a new port adress – more or less – randomly. When the package is called, it creates a file .wp-env.json in the directory where it was called. With this .wp-env.json file you can customize the WordPress installation. In our case dynamic rendered port numbers.
Port number generation
The last step is to check whether the generated numbers are already in use (port is open) at the time of generation. 🙂
Install / Remove
Install the package globally on your local computer:
npm install -g wp-env-port-stamp
To remove the package:
npm uninstall -g wp-env-port-stamp
- Go in your local dev environment to your plugin, theme or block root directory or wherever you want to start wp-env.
- Call the package:
- The file is generated. You can start now with
Normally you only need to call the package for the first time in a new project. Later just start directly wp-env.
Attention: If there is already existing .wp-env.json file, wp-env-port-stamp will overwrite it! (There will be an improvement for this later.) That was improved.
- Existing files are no longer overwritten.
- The range for the port numbers was increased.
- A filter now ensures that certain frequently used ports (e.g. 8888) are not used.
- Add TypeScript
- Add ESLint
- Add npm version badge
- Check if ports are already in use