gylaz
gylaz

Reputation: 13581

Docker cli: docker run command with quoted arguments

I'm trying to run execute jest -t variant with the following Docker cli command:

docker run -it node-jest npx jest -t "This string matches exactly one test"

Which does not do the same thing if I were to run npx jest -t "This string matches exactly one test" locally.

It appears that double quotes are being stripped/ignored and only This is getting passed to jest -t. It appears that This string matches exactly one test is getting split up on spaces and treated as individual arguments. Can someone explain why that is happening, and how to get "This string matches exactly one test" passed in to docker run correctly (hopefully in a readable/sane way)?

Upvotes: 4

Views: 676

Answers (1)

Adiii
Adiii

Reputation: 59966

You did not mention the error, and the quotes seems fine and it should work or run the container with shell, but my assumption is you did not set the WORKING directory in your Dockerfile or there is something wrong with Dockerfile

Here is working example taking from jest docker image with some testing code.

docker run -ti adiii717/jest sh -c 'npx jest -t "it should filter by a search term (link)"'

output:

Ran all test suites with tests matching "it should filter by a search term (link)".

-----------------|----------|----------|----------|----------|-------------------|
File             |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files        |     12.5 |        0 |        0 |    16.67 |                   |
 filterByTerm.js |     12.5 |        0 |        0 |    16.67 |         2,3,4,5,6 |
-----------------|----------|----------|----------|----------|-------------------|
Test Suites: 1 skipped, 0 of 1 total
Tests:       3 skipped, 3 total
Snapshots:   0 total
Time:        1.109s
Ran all test suites with tests matching "it should filter by a search term (link)".

Here is the Dockerfile

FROM node:alpine
RUN apk add --no-cache git
RUN npm install jest npx -g
WORKDIR /app
RUN git clone https://github.com/valentinogagliardi/getting-started-with-jest.git /app
RUN npm install

Upvotes: 1

Related Questions