Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why call from makefile returns empty result while same call from console does not?

I want to do shortcut with Makefile to delete docker image after i rebuild one of the services with docker-compose up --build, because dangling images are created with every rebuild.

My solution get image_id of stoped container and docker rmi it. As part if this a have to obtain image id, which i do like this:

export CONTAINER=name_1
docker container inspect --format='{{.Image}}' $CONTAINER
# > sha256:xxxxxxxxxxxxxxxxxxxxxx

But i get empty ouput from it if i call with makefile:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

./Makefile

CONTAINER=name_1
cmd:
    echo $(docker container inspect --format='{{.Image}}' $CONTAINER)
cmd
# > echo 

I do not understard what is the problem here.

>Solution :

This:

echo $(docker container inspect --format='{{.Image}}' $CONTAINER)

does not run docker. $ is special to make and it introduces a make variable, so you are expanding a very oddly-named (and empty) variable. You have to escape all $ as $$ in your recipe to hide it from make.

Also, makefile variable references that are >1 character long must be enclosed in either () or {} (they are equivalent):

echo $$(docker container inspect --format='{{.Image}}' ${CONTAINER})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading