1

I've got a repo with some NPM convenience scripts to run some basic docker commands:

  "scripts": {
    "build": "docker build -t myreadyapi --build-arg LICENSE_SERVER=1.1.1.1 .",
    "prestart": "npm run build",
    "start": "docker run -p 8089:8088 myreadyapi",
    "debug": "docker exec -it $(docker ps -a -q --filter ancestor=myreadyapi) /bin/bash",
    "stop": "docker rm $(docker stop $(docker ps -a -q --filter ancestor=myreadyapi))"
  }

npm run build and npm run start work, but npm run debug and npm run stop cause an error:

Error: No such container: $(docker

Note: running this from Windows 10 PowerShell console.

The error happens for any docker script that has a command parameter (i.e. docker ... $(docker ...)).

Has anyone encountered this before and knows how to fix this?

Cheers.

2 Answers 2

0

It may happen that you have some stopped containers that match $(docker ps -a -q --filter ancestor=myreadyapi).
Or no container is found with matching filter.
One solution could be crate random container name and use that name in further commands or set ancestor system generated value.

Sign up to request clarification or add additional context in comments.

4 Comments

If I run the command directly in the console it works... it's just when I run it via NPM
So, how does start work. After running the docker container, when it moves to debug does start exits. If that is the case try to change start as docker run -d -p 8089:8088 myreadyapi to run container as daemon.
I don't think it has anything to do with the docker commands - they all work perfectly fine when run directly from the command line. The issue is when trying to run docker commands (specifically ones that have command parameters) via an NPM script e.g. 'npm run debug'.
They all work via the command line, but only build and start work via NPM. What's common in the stop and debug scripts that's causing them not to work? Command parameters is one thing... this is also highlighted in the error message - "Error: No such container: $(docker"
0

I was able to get this working by adding "@powershell" in front of the command. That assumes Powershell is in your path

EG

"docker:stop":"@powershell docker rm $(docker stop $(docker ps -a -q --filter ancestor=myreadyapi))"

Referencing this answer

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.