version: '3.8'
services:
php:
build:
context: .
dockerfile: Dockerfile
container_name: my-laravel-app
working_dir: /var/www
volumes:
- C:\project\laravelProject:/var/www #마운트
networks:
- laravel-network
nginx:
image: nginx:alpine
container_name: my-laravel-nginx
ports:
- "80:80"
volumes:
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- C:\project\laravelProject:/var/www #마운트
networks:
- laravel-network
depends_on:
- php
extra_hosts:
- "test.co.kr:100.000.00.000" #필요한 호스트 등록
mariadb:
image: mariadb:10.4.21
container_name: my-laravel-mariadb
restart: unless-stopped
environment:
MYSQL_DATABASE: laravel
MYSQL_USER: laraveluser
MYSQL_PASSWORD: secret
MYSQL_ROOT_PASSWORD: secret
volumes:
- dbdata:/var/lib/mysql
ports:
- "3306:3306"
networks:
- laravel-network
redis:
image: redis:alpine
container_name: my-laravel-redis
ports:
- "6379:6379" # 호스트의 포트 3306을 컨테이너의 포트 3306에 매핑합니다.
networks:
- laravel-network
networks:
laravel-network:
volumes:
dbdata:
FROM php:7.4-fpm
# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
# Install PHP extensions
RUN apt-get update && apt-get install -y \
libonig-dev \
build-essential \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
locales \
zip \
jpegoptim \
optipng \
pngquant \
gifsicle \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
vim \
git \
curl \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apt-get update && docker-php-ext-install \
mbstring \
&& docker-php-ext-enable \
mbstring
RUN apt-get update && docker-php-ext-install \
exif \
&& docker-php-ext-enable \
exif
RUN apt-get update && docker-php-ext-install \
pcntl \
&& docker-php-ext-enable \
pcntl
RUN apt-get update && docker-php-ext-install \
bcmath \
&& docker-php-ext-enable \
bcmath
RUN apt-get update && docker-php-ext-install \
gd \
&& docker-php-ext-enable \
gd
RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-install zip
RUN apt-get update
# 필요한 패키지 설치
RUN apt-get update && apt-get install -y \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-enable pdo_mysql
# RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Set working directory
WORKDIR /var/www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
server {
listen 80;
index index.php index.html;
server_name localhost;
root /var/www/public;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
// docker-compose 파일 내
docker-compose-up -d
My-laravel-app 터미널 접속
composer install
php artisan migrate
장점
단점
// 도커 내리기
docker-compose down
// 도커 올리기
docker-compose up -d
// 도커 볼륨삭제
docker-compose down --volumes --remove-orphans
// 도커 이미지 강제 삭제
docker image prune --all --force
// 도커 컨테이너 목록
docker ps
// 도커 재빌드
docker-compose build
// 도커 특정 서비스 재시작
docker-compose restart {service}