The easiest way to do this is to install Node and run the npm
commands directly on the host.
$BREW_OR_APT_GET_OR_YUM_OR_SOMETHING install node
npm install
npm run dist
# done
There's not an easy way to use a Dockerfile to build host content. The Dockerfile can't write out directly to the host filesystem; if you use a volume mount, the host volume hides the container content before anything else happens.
That means, if you want to use this approach, you need to launch a temporary container to get the content out. You can do it with a one-off container, mounting the host directory somewhere other than /app
, making the main container command be cp
:
sudo docker build -t myimage .
sudo docker run --rm
-v "$PWD/dist:/out"
myimage
cp -a /app/dist /out
Or, if you specifically wanted to use docker cp
:
sudo docker build -t myimage .
sudo docker create --name to-copy myimage
sudo docker cp -r to-copy:/app/dist ./dist
sudo docker rm to-copy
Note that any of these sequences are more complex than just installing a local Node via a package manager, and require administrator permissions (you can use the same technique to overwrite any host file, including the /etc/shadow
file with encrypted passwords).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…