ideasonpurpose/docker-wordpress-dev

Config alternative for setting ports

Closed this issue · 2 comments

https://github.com/ideasonpurpose/docker-wordpress-dev/blob/master/README.md#alternate-devserver-ports

This broke in npm v7, based on RFC 21

Alternate DevServer Ports

Webpack devserver runs on port 8080 by default. Multiple projects can be run simultaneously by using npm config to assign different ports the the project's package.json name. For example, three projects named csr-site, pro-bono and ar-project could be run simultaneously on custom ports, after running these commands:

npm config set csr-site:port 8080
npm config set pro-bono:port 8081
npm config set ar-project:port 8082

See also:

Could this be an argument to the tools invocation? npm run start would default to port 8080, npm run start 8081 would run on port 8081. Is it possible to pass a command line arg into an npm script? Difficult? The start script is just a wrapper for an ugly docker compose command.

Yes! Going with npm run start --port=8531 which would set the environment variable $npm_config_port to 8531. The docker compose files recognize this variable and pass it through.

Invocation scripts now call docker compose with --service-ports. This lets us define ports in docker-compose.json and to keep the package.json scripts a little cleaner.