I am trying to create a Makefile target which first checks to see if my Docker container exists. If it exists then I want to issue the Docker Container Restart command otherwise I want to issue the Docker Run command to create and start the container.
I have coded the below but am getting the error shown below. The result = 1 is correct as I do have a container running. I have removed the container and tested that the result then becomes 0 which is also correct. The problem seems to be when I try to use result in the ifeq
statement. Can someone please advise me what I am doing wrong? (I have temporarily commented out the docker commands and replaced them with echo true / false just while I am debugging).
start_docker_myapp:
result = $(shell (docker ps -a | grep myapp ) | wc -l )
ifeq (${result}, 1)
@echo 'true'
# docker restart ${IMAGE}
else
@echo 'false'
# docker run -v ${DIR}/var/log/docker:/var/log/myapp -p 1812:1812/udp -p 1813:1813/udp --detach --name ${IMAGE} $(REGISTRY)/$(IMAGE):$(TAG)
endif
Output from Terminal
$ make start_docker_myapp result = 1 make: result: No such file or directory make: *** [start_docker_myapp] Error 1 $
make
is to run commands depending on comparisons of file modification dates. You don't do this in your Makefile. A shell script (or a set of shell scripts) might be better suited for your use case.${IMAGE}
and Make variables like$(IMAGE)
. Do you intend to use Make variables? You should show how you define these variables.$(...)
or${...}