Skip to content

Commit 4ce20d7

Browse files
author
seungwonme
committed
Finish inception project
1 parent 79e1411 commit 4ce20d7

File tree

18 files changed

+2707
-400
lines changed

18 files changed

+2707
-400
lines changed

docker/inception/Makefile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,40 @@ BG_DEFAULT = \033[49m
2828
RESET = \033[0m
2929

3030
up:
31-
@docker-compose up -d
32-
@echo "$(FG_GREEN)Connect to $(FG_WHITE)$(UNDERLINE)http://localhost$(RESET)"
31+
@docker-compose -f srcs/docker-compose.yml up -d
32+
@echo "$(FG_GREEN)Connect to $(FG_WHITE)$(UNDERLINE)https://localhost$(RESET)"
3333

3434
build:
35-
@docker-compose build
35+
@docker-compose -f srcs/docker-compose.yml build
3636

3737
down:
38-
@docker-compose down
38+
@docker-compose -f srcs/docker-compose.yml down
3939
@echo "$(FG_RED)Disconnected$(RESET)"
4040

4141
stop:
42-
@docker-compose stop
42+
@docker-compose -f srcs/docker-compose.yml stop
4343
@echo "$(YELLOW)Stopped$(RESET)"
4444

4545
start:
46-
@docker-compose start
4746
@echo "$(FG_GREEN)Started$(RESET)"
47+
@docker-compose -f srcs/docker-compose.yml start
48+
@echo "$(FG_GREEN)Connect to $(FG_WHITE)$(UNDERLINE)https://localhost$(RESET)"
4849

4950
re:
5051
@echo "$(FG_GREEN)Restarted$(RESET)"
51-
@docker-compose restart
52+
@docker-compose -f srcs/docker-compose.yml restart
53+
@echo "$(FG_GREEN)Connect to $(FG_WHITE)$(UNDERLINE)https://localhost$(RESET)"
5254

5355
logs:
5456
@echo "$(FG_CYAN)Logging$(RESET)"
55-
@docker-compose logs -f
57+
@docker-compose -f srcs/docker-compose.yml logs -f
5658

5759
ps:
5860
@echo "$(FG_MAGENTA)Status$(RESET)"
59-
@docker-compose ps
61+
@docker-compose -f srcs/docker-compose.yml ps
6062

6163
clean:
62-
@docker-compose down -v
64+
@docker-compose -f srcs/docker-compose.yml down -v
6365
@docker system prune -af --volumes
6466
@echo "$(FG_BLUE)Cleaned up$(RESET)"
6567

docker/inception/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[Docker Compose를 이용하여 워드프레스 설치하기 > 우분투 서버 | 우성짱의 NAS](https://www.wsgvet.com/bbs/board.php?bo_table=ubuntu&wr_id=97)
2+
3+
[custom setup](https://codingwithmanny.medium.com/custom-wordpress-docker-setup-8851e98e6b8)
4+
5+
6+
[WordPress Installation](https://www.hostinger.com/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu/?ppc_campaign=google_search_generic_hosting_all&bidkw=defaultkeyword&lo=1009871)
7+
8+
[Setup WordPress on Ubuntu 22.04 with Nginx and MariaDB | Works With The Web](https://www.workswiththeweb.com/wordpress/2024/01/14/Setup-WordPress-Ubuntu-Nginx/)
9+
10+
11+
Docker 볼륨 내의 컨텐츠를 확인하는 방법 중 하나는 Docker 컨테이너를 사용하여 해당 볼륨을 마운트하고, 그 내부를 탐색하는 것입니다. 위에서 제공된 출력을 바탕으로, `srcs_dbdata` 볼륨 안의 컨텐츠를 확인하는 방법을 설명하겠습니다.
12+
13+
1. **임시 컨테이너 생성 및 볼륨 마운트**
14+
15+
볼륨 내용을 확인하기 위해, 임시 컨테이너를 생성하고 `srcs_dbdata` 볼륨을 마운트할 수 있습니다. 이를 위해, 일반적으로 사용되는 `alpine` 이미지(또는 다른 Linux 배포판)를 사용할 수 있습니다. `alpine`은 가벼운 Linux 배포판으로, 파일 탐색에 필요한 기본 도구를 제공합니다.
16+
17+
```bash
18+
docker run -it --rm --volume srcs_dbdata:/data alpine sh
19+
```
20+
21+
위 명령어는 다음과 같이 작동합니다:
22+
- `docker run`: 새로운 컨테이너를 실행합니다.
23+
- `-it`: 대화형 터미널을 활성화합니다.
24+
- `--rm`: 컨테이너가 종료되면 자동으로 제거합니다.
25+
- `--volume srcs_dbdata:/data`: `srcs_dbdata` 볼륨을 컨테이너의 `/data` 디렉토리에 마운트합니다.
26+
- `alpine`: 사용할 이미지입니다.
27+
- `sh`: 실행할 명령입니다. `sh` 셸을 시작합니다.
28+
29+
2. **볼륨 내부 탐색**
30+
31+
컨테이너 내부에서 `/data` 디렉토리로 이동하여 볼륨 내부를 탐색할 수 있습니다.
32+
33+
```bash
34+
cd /data
35+
ls -l
36+
```
37+
38+
- `cd /data`: `/data` 디렉토리로 이동합니다.
39+
- `ls -l`: 현재 디렉토리의 파일 및 디렉토리 목록을 상세하게 출력합니다.
40+
41+
3. **필요한 작업 수행**
42+
43+
볼륨 내부에서 필요한 모든 작업을 수행할 수 있습니다. 예를 들어, 파일을 읽거나, 수정하거나, 새 파일을 생성할 수 있습니다.
44+
45+
4. **컨테이너 종료**
46+
47+
작업을 마친 후에는 `exit` 명령을 입력하여 컨테이너에서 나갈 수 있습니다. `--rm` 플래그가 설정되어 있으므로, 컨테이너는 자동으로 제거됩니다.
48+
49+
이 방법을 사용하면 별도의 서비스 중단 없이 Docker 볼륨 내의 데이터를 안전하게 탐색하고 관리할 수 있습니다.
50+
51+
이런 자료를 참고했어요.
52+
[1] Learn Microsoft - 볼륨 인식 방법 - Windows drivers (https://learn.microsoft.com/ko-kr/windows-hardware/drivers/ifs/how-the-volume-is-recognized)
53+
[2] Autodesk - Flame에 대한 vic(볼륨 무결성 확인) 사용 방법 (https://www.autodesk.co.kr/support/technical/article/caas/sfdcarticles/sfdcarticles/KOR/Using-vic-Volume-Integrity-Check.html)
54+
[3] AWS Documentation - Amazon EBS 볼륨에 대한 정보 보기 (https://docs.aws.amazon.com/ko_kr/ebs/latest/userguide/ebs-describing-volumes.html)
55+
[4] Microsoft Community - 사내 전체 볼륨 라이센스 제품키 확인 (https://answers.microsoft.com/ko-kr/windows/forum/all/%EC%82%AC%EB%82%B4-%EC%A0%84%EC%B2%B4/079b4530-5b1b-4025-b410-334cf6cf55e7)
56+
57+
뤼튼 사용하러 가기 > https://agent.wrtn.ai/5xb91l

docker/inception/srcs/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ DOMAIN_NAME=seunan.42.fr
22

33
# MYSQL SETUP
44
MYSQL_ROOT_PASSWORD=rt0406
5+
MYSQL_DATABASE=wordpress
56
MYSQL_USER=seunan
67
MYSQL_PASSWORD=db0406

docker/inception/srcs/docker-compose.yml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1+
# https://github.com/compose-spec/compose-spec/blob/master/spec.md
2+
# https://github.com/docker/awesome-compose/blob/master/official-documentation-samples/wordpress/README.md
3+
14
services:
25
mariadb:
36
build:
47
context: ./requirements/mariadb
58
# dockerfile: Dockerfile # 파일명이 Dockerfile이 아니면 명시해줘야 함
69
container_name: mariadb
7-
restart: unless-stopped
10+
restart: on-failure
811
env_file: .env
912
# .env 파일에 정의된 것 외에 추가 환경 변수를 추가
1013
environment:
11-
- MYSQL_DATABASE=wordpress
14+
- MYSQL_DATABASE=$MYSQL_DATABASE
1215
# dbdata라는 명명된 볼륨을 /var/lib/mysql 디렉토리에 마운트
16+
ports:
17+
- "3306"
1318
volumes:
1419
- dbdata:/var/lib/mysql
1520
# 이미지에 대한 기본 CMD 지침을 재정의
16-
command: "--default-authentication-plugin=mysql_native_password"
21+
# command: "--default-authentication-plugin=mysql_native_password"
1722
networks:
1823
- app-network
1924
wordpress:
@@ -22,13 +27,15 @@ services:
2227
build:
2328
context: ./requirements/wordpress
2429
container_name: wordpress
25-
restart: unless-stopped
30+
restart: on-failure
2631
env_file: .env
2732
environment:
2833
- WORDPRESS_DB_HOST=mariadb:3306
2934
- WORDPRESS_DB_USER=$MYSQL_USER
3035
- WORDPRESS_DB_PASSWORD=$MYSQL_PASSWORD
31-
- WORDPRESS_DB_NAME=wordpress
36+
- WORDPRESS_DB_NAME=$MYSQL_DATABASE
37+
ports:
38+
- "9000"
3239
volumes:
3340
- wordpress:/var/www/html
3441
networks:
@@ -39,27 +46,15 @@ services:
3946
build:
4047
context: ./requirements/nginx
4148
container_name: webserver
42-
restart: unless-stopped
49+
restart: on-failure
4350
ports:
44-
- "80:80"
51+
- "443:443"
4552
volumes:
4653
- wordpress:/var/www/html
47-
- ./nginx-conf:/etc/nginx/conf.d
48-
- certbot-etc:/etc/letsencrypt
4954
networks:
5055
- app-network
51-
certbot:
52-
depends_on:
53-
- webserver
54-
image: certbot/certbot
55-
container_name: certbot
56-
volumes:
57-
- certbot-etc:/etc/letsencrypt
58-
- wordpress:/var/www/html
59-
command: certonly --webroot --webroot-path=/var/www/html --email [email protected] --agree-tos --no-eff-email --staging -d seunan.42.fr -d www.seunan.42.fr
6056

6157
volumes:
62-
certbot-etc:
6358
wordpress:
6459
dbdata:
6560

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1+
# https://github.com/yobasystems/alpine-mariadb/blob/master/alpine-mariadb-aarch64/Dockerfile
2+
13
# Base image
24
FROM alpine:3.18
35

4-
RUN apk update \
5-
&& apk add mariadb-server
6+
RUN apk update && \
7+
apk add --no-cache mariadb mariadb-client mariadb-server-utils && \
8+
rm -rf /var/cache/apk/* && \
9+
mkdir -p /scripts /var/log/mysql/ && \
10+
touch /var/log/mysql/error.log && \
11+
chown -R mysql:mysql /var/log/mysql/
612

713
EXPOSE 3306
814

9-
HEALTHCHECK --start-period=5m \
10-
CMD mariadb -e 'SELECT @@datadir;' || exit 1
15+
COPY tools/run.sh /scripts/run.sh
16+
COPY conf/mariadb-server.cnf /etc/my.cnf.d/mariadb-server.cnf
17+
18+
RUN chmod -R 755 /scripts
19+
20+
# HEALTHCHECK --start-period=5m \
21+
# CMD mariadb -e 'SELECT @@datadir;' || exit 1
22+
23+
VOLUME ["/var/lib/mysql"]
1124

12-
CMD ["mariadbd"]
25+
ENTRYPOINT ["/scripts/run.sh"]
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# MariaDB Container
22

33
[MariaDB - Alpine Linux](https://wiki.alpinelinux.org/wiki/MariaDB)
4-
[Running mysql in the foreground in centos - Stack Overflow](https://stackoverflow.com/questions/24563762/running-mysql-in-the-foreground-in-centos)
54
[MariaDB](https://mariadb.com/kb/en/creating-a-custom-container-image/)
5+
6+
[Mysql 사용자 조회/추가/생성/삭제](https://technote.kr/32)
7+
[SQL 기초 & 자주쓰는 쿼리문 정리](https://365kim.tistory.com/102)
8+
[Create a new MariaDB database and user](https://docs.bitnami.com/virtual-machine/apps/wordpress/configuration/create-database-mariadb/)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#
2+
# These groups are read by MariaDB server.
3+
# Use it for options that only the server (but not clients) should see
4+
5+
# this is read by the standalone daemon and embedded servers
6+
[server]
7+
8+
# this is only for the mysqld standalone daemon
9+
[mysqld]
10+
log_error = /var/log/mysql/error.log
11+
skip-networking
12+
13+
# Galera-related settings
14+
[galera]
15+
# Mandatory settings
16+
#wsrep_on=ON
17+
#wsrep_provider=
18+
#wsrep_cluster_address=
19+
#binlog_format=row
20+
#default_storage_engine=InnoDB
21+
#innodb_autoinc_lock_mode=2
22+
#
23+
# Allow server to accept connections on all interfaces.
24+
#
25+
bind-address=0.0.0.0
26+
#
27+
# Optional setting
28+
#wsrep_slave_threads=1
29+
#innodb_flush_log_at_trx_commit=0
30+
31+
# this is only for embedded server
32+
[embedded]
33+
34+
# This group is only read by MariaDB servers, not by MySQL.
35+
# If you use the same .cnf file for MySQL and MariaDB,
36+
# you can put MariaDB-only options here
37+
[mariadb]
38+
39+
# This group is only read by MariaDB-10.5 servers.
40+
# If you use the same .cnf file for MariaDB of different versions,
41+
# use this group for options that older servers don't understand
42+
[mariadb-10.5]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
# https://github.com/yobasystems/alpine-mariadb/blob/master/alpine-mariadb-aarch64/files/run.sh
3+
4+
if [ -d "/run/mysqld" ]; then
5+
chown -R mysql:mysql /run/mysqld
6+
else
7+
mkdir -p /run/mysqld
8+
chown -R mysql:mysql /run/mysqld
9+
fi
10+
11+
if [ -d /var/lib/mysql/mysql ]; then
12+
chown -R mysql:mysql /var/lib/mysql
13+
else
14+
chown -R mysql:mysql /var/lib/mysql
15+
16+
mysql_install_db --user=mysql --ldata=/var/lib/mysql > /dev/null
17+
18+
tfile=`mktemp` # https://www.tutorialspoint.com/unix_commands/mktemp.htm
19+
if [ ! -f "$tfile" ]; then
20+
return 1
21+
fi
22+
23+
cat << EOF > $tfile
24+
25+
USE mysql;
26+
FLUSH PRIVILEGES ;
27+
GRANT ALL ON *.* TO 'root'@'%' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION ;
28+
GRANT ALL ON *.* TO 'root'@'localhost' identified by '$MYSQL_ROOT_PASSWORD' WITH GRANT OPTION ;
29+
GRANT ALL ON wordpress.* TO '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' WITH GRANT OPTION;
30+
GRANT ALL ON wordpress.* TO '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD' WITH GRANT OPTION;
31+
SET PASSWORD FOR 'root'@'localhost'=PASSWORD('${MYSQL_ROOT_PASSWORD}') ;
32+
CREATE DATABASE wordpress;
33+
DROP DATABASE IF EXISTS test ;
34+
FLUSH PRIVILEGES ;
35+
EOF
36+
37+
/usr/bin/mysqld --user=mysql --bootstrap --verbose=0 --skip-name-resolve --skip-networking=0 < $tfile
38+
# rm -f $tfile
39+
fi
40+
41+
exec /usr/bin/mysqld --user=mysql --console --skip-name-resolve --skip-networking=0 $@
42+
43+
# mysql -u root -p$MYSQL_ROOT_PASSWORD -e "CREATE DATABASE wordpress;"
44+
# mysql -u root -p$MYSQL_ROOT_PASSWORD -e "CREATE USER '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD';"
45+
# mysql -u root -p$MYSQL_ROOT_PASSWORD -e "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD';"
46+
# mysql -u root -p$MYSQL_ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON wordpress.* TO '$MYSQL_USER'@'localhost';"
47+
# mysql -u root -p$MYSQL_ROOT_PASSWORD -e "GRANT ALL PRIVILEGES ON wordpress.* TO '$MYSQL_USER'@'%';"
48+
# mysql -u root -p$MYSQL_ROOT_PASSWORD -e "FLUSH PRIVILEGES;"

docker/inception/srcs/requirements/nginx/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Base image
22
FROM alpine:3.18
33

4-
RUN apk update \
5-
&& apk add --no-cache nginx openssl \
6-
&& mkdir -p /var/www/html /var/www/css /etc/nginx/ssl \
7-
&& openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/C=KR/ST=Seoul/L=Seoul/O=42Seoul/OU=Cadet/CN=localhost"
4+
RUN apk update && \
5+
apk add --no-cache nginx openssl && \
6+
mkdir -p /etc/nginx/ssl /var/www/html && \
7+
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/C=KR/ST=Seoul/L=Seoul/O=42Seoul/OU=Cadet/CN=localhost"
88

99
# Copy the configuration file
1010
COPY conf/default.conf /etc/nginx/http.d/default.conf
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
# This is a default site configuration which will simply return 404, preventing
2-
# chance access to any other virtualhost.
31
server {
4-
listen 80 default_server;
5-
listen [::]:80 default_server;
2+
listen 443 ssl default_server; # 443번 포트를 사용하고, 기본 서버로 설정한다. IPv4
3+
listen [::]:443 ssl default_server; # 윗줄과 동일하나, IPv6
4+
server_name localhost;
65

7-
root /var/www/localhost/htdocs;
8-
index index.php index.html index.htm;
6+
# SSL Configuration
7+
ssl_certificate /etc/nginx/ssl/nginx.crt;
8+
ssl_certificate_key /etc/nginx/ssl/nginx.key;
9+
ssl_protocols TLSv1.3;
10+
ssl_ciphers HIGH:!aNULL:!MD5; # HIGH: 모든 암호화 알고리즘을 사용하되, aNULL과 MD5는 사용하지 않는다.
11+
12+
root /var/www/html; # 웹 서버의 루트 디렉토리를 설정한다.
13+
index index.php index.html index.htm; # 기본 문서를 설정(우선순위 순서대로)
914
location / {
1015
try_files $uri $uri/ /index.php?$query_string;
1116
}
12-
# You may need this to prevent return 404 recursion.
17+
18+
# 특정 경로에 대한 설정을 정의하는 블록
1319
location = /404.html {
1420
internal;
1521
}
22+
1623
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
1724
location ~ \.php$ {
1825
try_files $uri /index.php =404;
1926
fastcgi_split_path_info ^(.+\.php)(/.+)$;
20-
fastcgi_pass 0.0.0.0:9000;
27+
fastcgi_pass wordpress:9000;
2128
fastcgi_index index.php;
2229
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
2330
include fastcgi_params;
2431
}
32+
33+
# Client request size limit: 클라이언트가 보낼 수 있는 요청 본문의 최대 크기를 제한하여 이는 대량의 데이터 업로드를 방지하거나 DDoS 공격을 완화하는 데 도움
34+
client_max_body_size 10m;
2535
}

0 commit comments

Comments
 (0)