V
V
Vadim2021-07-20 19:40:25
Node.js
Vadim, 2021-07-20 19:40:25

How to run this command without a script?

Hello everyone,

I can run the following command in my frontend project folder

docker run --rm -v ${PWD}/:/var/task -u 0 node:15-alpine sh /var/task/myscript.sh


in the myscript.sh file I put

cd /var/task && npm install && npm ci

when I try to do the same but with the command
docker run --rm -v ${PWD}/:/var/task -u 0 node:15-alpinealpine sh " cd /var/task && npm install && npm ci"

an error is thrown - can you tell me why and... what do you recommend, the script creates some inconvenience

for everyone,
Vadim

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Karabanov, 2021-07-20
@Viji

We call help:

docker run --rm -v ${PWD}/:/var/task -u 0 node:15-alpine sh --help
BusyBox v1.31.1 () multi-call binary.

Usage: sh [-/+OPTIONS] [-/+o OPT]... [-c 'SCRIPT' [ARG0 [ARGS]] / FILE [ARGS] / -s [ARGS]]

Unix shell interpreter

Thus:
docker run --rm -v ${PWD}/:/var/task -u 0 node:15-alpine sh -c "cd /var/task && npm install && npm ci"

And it's possible like this:
docker run --rm -v ${PWD}/:/var/task -u 0 --workdir="/var/task" node:15-alpine sh -c "npm install && npm ci

Or generally like this:
docker run --rm -v ${PWD}/:/var/task -u 0 --workdir="/var/task" node:15-alpine npm install && npm ci

PS
https://docs.docker.com/engine/reference/run/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question