-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
98 lines (77 loc) · 1.87 KB
/
Copy pathMakefile
File metadata and controls
98 lines (77 loc) · 1.87 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Define shell to use
SHELL := /bin/bash
COMPOSE := docker compose -f srcs/docker-compose.yml
default: up
# Start up services
up:
$(COMPOSE) up -d --build
# Pause services
pause:
$(COMPOSE) pause
# Restart services
restart:
$(COMPOSE) restart
# Stop services
down:
$(COMPOSE) down
# Stop services and remove volumes
down-v:
$(COMPOSE) down -v
# Stop services, remove volumes and images
down-all:
$(COMPOSE) down -v --rmi all
# Show logs
logs:
$(COMPOSE) logs -f
# Show logs for a specific service (e.g., make logs-wordpress)
logs-%:
$(COMPOSE) logs -f $*
# Access shell inside a container (e.g., make shell-wordpress)
shell-%:
$(COMPOSE) exec $* /bin/sh
# Execute a command inside a running container (e.g., make exec service=wordpress cmd="ls")
exec:
$(COMPOSE) exec $(service) $(cmd)
# Stop all running containers
stop:
@containers=$$(docker ps -q); \
if [ -n "$$containers" ]; then \
docker stop $$containers; \
else \
echo "No containers to stop"; \
fi
# Remove all images
rmi:
@images=$$(docker images -aq); \
if [ -n "$$images" ]; then \
docker rmi -f $$images; \
else \
echo "No images to remove"; \
fi
# Remove all volumes
rmv:
@volumes=$$(docker volume ls -q); \
if [ -n "$$volumes" ]; then \
docker volume rm -f $$volumes; \
else \
echo "No volumes to remove"; \
fi
# Remove all networks
rmn:
@networks=$$(docker network ls --format '{{.Name}}' | grep -v 'bridge\|host\|none'); \
if [ -n "$$networks" ]; then \
docker network rm $$networks; \
else \
echo "No networks to remove"; \
fi
# Remove all containers
rmc:
@containers=$$(docker ps -aq); \
if [ -n "$$containers" ]; then \
docker rm -f $$containers; \
else \
echo "No containers to remove"; \
fi
# Remove all images, volumes, networks and containers
clean: stop down-all rmn rmv rmc rmi
.PHONY: default up down down-v down-all restart logs logs-% shell-% exec rmi rmv rmn rmc clean