问题
Sometimes you want to use a custom node version in your ddev setup. I will give an example configuration how this can be archived.
回答1:
Create a file in .ddev/ folder named docker-compose.node.yaml
with the following content:
version: '3.6'
# recent ddev requires docker-compose file version 3.6
services:
node:
container_name: ddev-${DDEV_SITENAME}-node
image: node:10.6
user: "node"
restart: "no"
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.platform: ddev
com.ddev.app-type: php
com.ddev.approot: $DDEV_APPROOT
volumes:
- "../:/var/www/html:cached"
working_dir: /var/www/html
command: ["tail", "-f", "/dev/null"]
Ddev will start a separate node container that is not terminated after startup.
You can ssh into that container using the command ddev ssh -s node
You can also configure post-start hook like this:
hooks:
post-start:
- exec-host: ddev exec -s node npm ci --quiet
- exec-host: ddev exec -s node npm start
来源:https://stackoverflow.com/questions/51731242/how-to-use-a-separate-node-container-in-your-ddev-setup