먼저 사용할 도커 이미지부터 다운로드한다.
apache2와 php, mysql 전부 사용할 예정이기에 모두 다운받아주도록 하자.
버전을 지정하지 않을경우 최신버전을 다운받게되니 원하는 버전이 있는경우 지정해주도록 한다.
docker pull <이미지>:<버전>
docker pull httpd docker pull php:7.4-fpm docker pull mysql:5.7
받은 이미지를 확인하고 싶으면 아래명령어로 확인을 한다.
docker images
docker 이미지를 실행시켜주는 docker-compose.yml파일을 아래와 같이 작성한다.
version: '3.9'
services:
apache2:
image: httpd:latest
container_name: apache2
ports:
- "8000:80"
volumes:
- ./Project:/var/www/html #프로젝트 경로
- ./apache2/httpd.conf:/usr/local/apache2/conf/httpd.conf #apache2 설정파일
#- ./apache2/httpd-vhosts.conf:/usr/local/apache2/conf/extra/httpd-vhosts.conf #apache2 가상호스트 파일
mysql:
image: mysql:5.7
container_name: mysql
restart: unless-stopped
tty: true
ports:
- "3306:3306"
environment:
MYSQL_HOST: localhost
MYSQL_DATABASE: dbname #디비명
MYSQL_USER: user #사용자명
MYSQL_PASSWORD: password #사용자비밀번호
MYSQL_ROOT_PASSWORD: password #루트계정비밀번호
SERVICE_TAGS: dev
SERVICE_NAME: mysql
php:
image: php:7.4-fpm
container_name: php
volumes:
- ./Project:/var/www/html #프로젝트 경로
ports:
- "9000:9000"
command:
- /bin/sh
- -c
- |
echo "security.limit_extensions = .php .phtml .php3 .php4 .php5 .html .htm" >> /usr/local/etc/php-fpm.d/www.conf
php-fpm
apache2와 php-fpm을 연결하기위해
apache2컨테이너의 httpd.conf파일만 변경하면된다.
파일을 작성한 경로에 apache2/httpd.conf를 생성한 다음
<Directory "/var/www/html">아래를 찾아 아래와 같이 수정해주면 된다.
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
<FilesMatch \.(php|phar|html)$>
SetHandler "proxy:fcgi://php:9000"
</FilesMatch>
</Directory>
docker-compose up --build # 첫 실행 docker-compose up -d # 추후 실행
docker-compose down