반응형
목표
Docker compose를 사용하여 Nginx, PHP, MySQL 컨테이너를 생성하고, Laravel 프로젝트의 개발환경을 구성한다.
파일구성
2-1. docker-compose.yml
version: "3.7"
services:
php:
build:
context: .
dockerfile: ./php/Dockerfile
restart: always
ports:
- "9000:9000"
expose:
- "9000"
volumes:
# - ./php/config/custom.ini:/usr/local/etc/php/conf.d/custom.ini
- ./app:/home/app
mysql:
image: mysql:8.0
restart: always
environment:
MYSQL_DATABASE: ${데이터베이스}
MYSQL_USER: ${유저명}
MYSQL_PASSWORD: ${유저패스}
MYSQL_ROOT_PASSWORD: ${root패스}
volumes:
# - ./mysql/dump:/docker-entrypoint-initdb.d
# - ./mysql/data:/var/lib/mysql:rw
ports:
- "3307:3306"
nginx:
image: nginx:latest
restart: always
volumes:
- ./app:/home/app
- ./nginx/logs:/var/log/nginx
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "80:80"
- "443:443"
2-2. php
build:
context: .
dockerfile: ./php/Dockerfile
restart: always
ports:
- "9000:9000"
expose:
- "9000"
volumes:
# - ./php/config/custom.ini:/usr/local/etc/php/conf.d/custom.ini
- ./app:/home/app
2-2-1. php Dockerfile
FROM php:8.2.5-fpm
RUN apt-get update
RUN apt-get install -y curl
#install some base extensions
RUN apt-get install -y \
zlib1g-dev \
zip \
libpng-dev \
exiftool \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libicu-dev \
libpq-dev \
libxpm-dev \
libvpx-dev \
libzip-dev \
mariadb-client \
libxml2-dev \
vim
RUN docker-php-ext-configure gd --enable-gd --with-freetype --with-jpeg
RUN docker-php-ext-install pdo_mysql exif gd bcmath zip
# Composer install
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
WORKDIR /home/app
CMD ["php-fpm"]
2-3. MySQL
image: mysql:8.0
restart: always
environment:
MYSQL_DATABASE: ${데이터베이스}
MYSQL_USER: ${유저명}
MYSQL_PASSWORD: ${유저패스}
MYSQL_ROOT_PASSWORD: ${root패스}
volumes:
# - ./mysql/dump:/docker-entrypoint-initdb.d
# - ./mysql/data:/var/lib/mysql:rw
ports:
- "3307:3306"
2-4. Nginx
image: nginx:latest
restart: always
volumes:
- ./app:/home/app
- ./nginx/logs:/var/log/nginx
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
ports:
- "80:80"
- "443:443"
2-4-1. default.conf
server {
listen 80;
server_name localhost;
root "/home/app/public";
index index.php index.html index.htm ;
charset utf-8;
location / {
add_header 'Access-Control-Allow-Origin' "*";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header Access-Control-Allow-Headers "X-Requested-With, X-Prototype-Version, X-CSRF-Token, x-csrftoken, Origin, Accept, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Authorization";
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log error;
sendfile off;
client_max_body_size 0;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
}
반응형
'Docker' 카테고리의 다른 글
Docker compose configuration (0) | 2024.04.04 |
---|---|
RabbitMQ Docker compose 구성하기 (0) | 2024.03.27 |
Docker 명령어 정리 (0) | 2024.01.15 |
executor failed running [/bin/sh -c apt-get update]: exit code: 100 이슈 (6) | 2023.08.18 |
Docker commit (0) | 2022.12.17 |