-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
56 lines (48 loc) · 1.57 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
IMAGE_NAME = bookstagram-uploader
CONTAINER_NAME = book-uploader
.PHONY: build run stop clean rebuild restart all
build:
@if [ -z "$$(docker images -q $(IMAGE_NAME))" ]; then \
echo "Building Docker image..."; \
docker build -t $(IMAGE_NAME) .; \
else \
echo "Docker image $(IMAGE_NAME) already exists. Skipping build."; \
fi
run:
@if [ -z "$$(docker ps -q -f name=$(CONTAINER_NAME))" ]; then \
echo "Running Docker container..."; \
docker run -d -p 5001:5000 --name $(CONTAINER_NAME) $(IMAGE_NAME); \
else \
echo "Docker container $(CONTAINER_NAME) is already running."; \
fi
stop:
@if [ ! -z "$$(docker ps -q -f name=$(CONTAINER_NAME))" ]; then \
echo "Stopping Docker container..."; \
docker stop $(CONTAINER_NAME); \
else \
echo "No running container named $(CONTAINER_NAME) to stop."; \
fi
clean:
@if [ ! -z "$$(docker ps -a -q -f name=$(CONTAINER_NAME))" ]; then \
echo "Stopping and removing Docker container..."; \
docker stop $(CONTAINER_NAME); \
docker rm $(CONTAINER_NAME); \
else \
echo "No running container named $(CONTAINER_NAME) to stop."; \
fi
@if [ ! -z "$$(docker images -q $(IMAGE_NAME))" ]; then \
echo "Removing Docker image..."; \
docker rmi $(IMAGE_NAME); \
else \
echo "No image named $(IMAGE_NAME) to remove."; \
fi
rebuild: clean build run
restart:
@if [ ! -z "$$(docker ps -q -f name=$(CONTAINER_NAME))" ]; then \
echo "Restarting Docker container..."; \
docker stop $(CONTAINER_NAME); \
docker start $(CONTAINER_NAME); \
else \
echo "No running container named $(CONTAINER_NAME) to restart."; \
fi
all: build run