-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
123 lines (103 loc) · 3.78 KB
/
Copy pathMakefile
File metadata and controls
123 lines (103 loc) · 3.78 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
LOGIN := $(shell whoami)
WP_DATA = /home/$(LOGIN)/data/wordpress #define the path to the wordpress data
DB_DATA = /home/$(LOGIN)/data/mariadb #define the path to the mariadb data
# default target
all: up
# Start the building process: create data directories, then start containers in the background.
up: build
@mkdir -p $(WP_DATA)
@mkdir -p $(DB_DATA)
@sudo chown -R $(LOGIN):$(LOGIN) $(WP_DATA) $(DB_DATA)
@sudo chmod 755 $(DB_DATA) $(WP_DATA)
@echo "🚀 Starting containers..."
docker compose -p inception -f ./srcs/docker-compose.yml up -d --remove-orphans
# Add network creation to ensure it exists
create-network:
@echo "🌐 Creating Docker network..."
@docker network create inception || true
bonus: down create-network
@echo "🚀 Starting all containers..."
@docker compose -p inception\
-f ./srcs/docker-compose.yml \
-f ./srcs/docker-compose.bonus.yml \
up -d --build
down:
@echo "🛑 Stopping all containers..."
@docker compose -p inception\
-f ./srcs/docker-compose.yml \
-f ./srcs/docker-compose.bonus.yml \
down --remove-orphans
# Stop the containers
stop:
@echo "🛑 Stopping bonus containers"
docker compose -f ./srcs/docker-compose.bonus.yml stop || true
@echo "🛑 Stopping mandatory containers"
docker compose -f ./srcs/docker-compose.yml stop
# Start the containers
start:
@echo "🚀 Starting mandatory containers"
docker compose -f ./srcs/docker-compose.yml start
@echo "🚀 Starting bonus containers"
docker compose -f ./srcs/docker-compose.bonus.yml start || true
# Build the containers
build:
@echo "🏗️ Building mandatory containers"
docker compose -f ./srcs/docker-compose.yml build
# Clean the containers: stop and remove containers, volumes, network, and local data directories.
clean:
@echo "🧹 Stopping and removing containers..."
@docker compose -p inception \
-f ./srcs/docker-compose.yml \
-f ./srcs/docker-compose.bonus.yml \
down --volumes --remove-orphans || true
@echo "🗑️ Cleaning network..."
@docker network rm inception || true
@echo "🗑️ Pruning Docker system..."
@docker volume rm mariadb wordpress || true
@docker system prune -af || true
@echo "🧨 Cleaning data directories..."
@sudo rm -rf $(WP_DATA)
@sudo rm -rf $(DB_DATA)
@echo "📁 Recreating empty directories..."
@mkdir -p $(WP_DATA)
@mkdir -p $(DB_DATA)
@sudo chown -R $(LOGIN):$(LOGIN) $(WP_DATA) $(DB_DATA)
@sudo chmod 755 $(WP_DATA) $(DB_DATA)
@echo "✨ Clean complete!"
# Clean and start the containers
re: clean up
# Prune: run clean, then docker system prune (all containers, images, volumes).
prune: clean
@echo "♻️ Pruning all Docker resources"
@docker system prune -a --volumes -f
.PHONY: all up down stop start build clean re prune bonus create-network
# Useful commands (replace <DOMAIN_NAME> with your DOMAIN_NAME from .env):
# curl -k https://localhost
# curl -k https://<DOMAIN_NAME>
# curl -k https://localhost/wp-admin
# curl -k https://<DOMAIN_NAME>/adminer
# Connect to Redis and test:
# docker exec -it redis redis-cli ping # Should return PONG
# docker logs redis
# Database operations:
# docker exec -it mariadb mysql -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DB
# Common MySQL commands:
# SHOW TABLES;
# SELECT * FROM wp_users;
# SELECT * FROM wp_posts LIMIT 5;
# Redis operations:
# docker exec -it redis redis-cli
# Common Redis commands:
# PING
# INFO
# MONITOR
# KEYS *
# Container management:
# docker logs -f wordpress # Follow WordPress logs
# docker logs -f nginx # Follow Nginx logs
# docker exec -it nginx bash # Shell into nginx
# docker exec -it wordpress bash # Shell into WordPress
# Network debugging:
# docker network inspect inception
# docker port nginx # Show port mappings
# docker stats # Monitor container resources