質問編集履歴

1

Dockerfile及びdocker-compose.ymlを追加

2025/03/09 03:47

投稿

matsu_918
matsu_918

スコア2

test CHANGED
File without changes
test CHANGED
@@ -17,6 +17,101 @@
17
17
 
18
18
  ### 該当のソースコード
19
19
 
20
+ ```dockercompose.yml
21
+ version: '3.9'
22
+
23
+ services:
24
+ backend:
25
+ build:
26
+ context: ./backend
27
+ container_name: backend-container
28
+ volumes:
29
+ - ../src:/var/www/html
30
+ ports:
31
+ - "80:80"
32
+ depends_on:
33
+ - db
34
+
35
+ frontend:
36
+ build:
37
+ context: ./frontend
38
+ container_name: frontend-container
39
+ working_dir: /var/www/html
40
+ ports:
41
+ - "5173:5173"
42
+ volumes:
43
+ - ../src:/var/www/html
44
+
45
+ batch:
46
+ build:
47
+ context: ./batch
48
+ container_name: batch-container
49
+ volumes:
50
+ - ../src:/var/www/html
51
+ depends_on:
52
+ - db
53
+
54
+ db:
55
+ image: mysql:latest
56
+ container_name: db-container
57
+ ports:
58
+ - "3306:3306"
59
+ environment:
60
+ MYSQL_ROOT_PASSWORD: root
61
+ MYSQL_DATABASE: laravel
62
+ MYSQL_USER: laravel
63
+ MYSQL_PASSWORD: laravel
64
+ volumes:
65
+ - db_data:/var/lib/mysql
66
+ - ./mysql/my.cnf:/etc/mysql/my.cnf
67
+
68
+ volumes:
69
+ db_data:
70
+ ```
71
+
72
+ ```Dockerfile
73
+ FROM php:8.4-cli
74
+
75
+ RUN apt-get update && apt-get install -y \
76
+ cron \
77
+ rsyslog \
78
+ curl \
79
+ zip \
80
+ unzip \
81
+ git \
82
+ libpng-dev \
83
+ libonig-dev \
84
+ libxml2-dev \
85
+ libzip-dev \
86
+ nano \
87
+ vim \
88
+ procps \
89
+ && docker-php-ext-install pdo_mysql mbstring exif pcntl bcmath gd zip
90
+
91
+ COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
92
+
93
+ # php.iniをコンテナ内にコピー
94
+ COPY php.ini /usr/local/etc/php/
95
+
96
+ # cron ジョブの設定をコピー
97
+ COPY crontab /etc/cron.d/batch-cron
98
+
99
+ # 設定ファイルの権限を変更
100
+ RUN chmod 0644 /etc/cron.d/batch-cron && \
101
+ crontab /etc/cron.d/batch-cron
102
+
103
+ WORKDIR /var/www/html
104
+
105
+ # cronのログ出力先を設定(/var/log/cron.log)
106
+ RUN echo "cron.* /var/log/cron.log" > /etc/rsyslog.d/cron-log.conf
107
+
108
+ # ログファイルがない場合に作成し、適切な権限を設定
109
+ RUN touch /var/log/cron.log && chmod 666 /var/log/cron.log
110
+
111
+ # cronとrsyslogをバックグラウンドで実行する
112
+ CMD cron && tail -f /var/log/cron.log
113
+ ```
114
+
20
115
  ```SampleJob.php
21
116
  <?php
22
117