1

I am running a yarn command inside node docker container and I'd like to change the working directory on docker run command. The current command I am using is:

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

I got this output:

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.

It seems that it tries to run cd as a script file. How can I change working directory without updating docker image?

2
  • Make sure the ; isn't being interpreted by your shell, but instead by the shell on the receiving end. You may need to quote the last argument. Consider: "cd /outputs && yarn ..." Commented Apr 18, 2020 at 23:27
  • If you're just trying to run Node, I'd suggest using an OS package or the download link on the front page of nodejs.org. Using Docker just to "not need to install" Node adds a lot of unnecessary complexity. Commented Apr 19, 2020 at 12:09

1 Answer 1

2

Use --workdir or -w instead of trying to cd:

docker run -v $(pwd)/$BUILDDIR:/outputs -it --rm -w /outputs node:12.16.2-alpine3.11 yarn install --only=production --pure-lockfile
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.