首页 > 解决方案 > 运行`node` docker容器时如何更改目录?

问题描述

yarn在节点 docker 容器中运行一个命令,我想更改 docker 命令上的目录。我正在使用的当前命令是:

docker run -v $(pwd)/$BUILDDIR:/outputs -it --rm node:12.16.2-alpine3.11 cd /outputs;yarn install --only=production --pure-lockfile

我得到了这个输出:

sh: can't open 'cd': No such file or directory
yarn install v1.22.4
[1/4]   Resolving packages...
success Already up-to-date.
✨  Done in 0.13s.

它似乎试图cd作为脚本文件运行。如何在不更新 docker 映像的情况下更改工作目录?

标签: docker

解决方案


使用--workdiror-w而不是尝试cd

docker run -v $(pwd)/$BUILDDIR:/outputs -it --rm -w /outputs node:12.16.2-alpine3.11 yarn install --only=production --pure-lockfile

推荐阅读