0

I have a Docker container running and I would like to kill it using make kill.

Here's my Makefile:

kill:
    CONTAINER=$(docker ps -a -q  --filter ancestor=container-name); \
    docker kill $$CONTAINER

It gives error:

CONTAINER=; \
docker kill $CONTAINER
"docker kill" requires at least 1 argument.
See 'docker kill --help'.

It seems that the variable CONTAINER is empty. However running in the shell:

$(docker ps -a -q  --filter ancestor=container-name)

Returns the container id, in fact it prints:

c1cddc4d19a0: command not found
0

1 Answer 1

1

I assume you have not defined a make variable named docker ps -a -q --filter ancestor=container-name, and you instead want to run that as a program and obtain its output.

If so, you need to escape the $ here like you did for the variable:

kill:
        CONTAINER=$$(docker ps -a -q  --filter ancestor=container-name); \
        docker kill $$CONTAINER

Otherwise make thinks that $(docker ps -a -q --filter ancestor=container-name) is a reference to a non-existent variable and will substitute the empty string.

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

1 Comment

Thanks for this! I was struggling with this line VERSION = $(git describe --tags --always || echo "unknown version") and it turned out I only needed to append the missing $ to the beginning (VERSION = $$(git describe --tags --always || echo "unknown version")

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.