利用 docker-compose 配置 php 开发环境

记录一次利用 docker-compose 搭建开发环境过程,避免重复配置

安装 docker 与 docker-compose

docker 在 win 和 macOS 都有安装包,linux 根据版本和官网教程可以安装。
docker-compose 安装参照官方教程。

docker-compose.yaml

version: "3"
services:
	php:
		image: php:7.0-fpm
		volumes:
      	 - .:/app
	nginx:
		image: nginx
		volumes:
		 - .:/app
		 - ./docker/nginx.conf:/etc/nginx/nginx.conf:ro
	mysql:
		image: mysql:5.6
		volumes:
		 - ./docker/mysqldata:/var/lib/mysql
		environment:
		 - MYSQL_ROOT_PASSWORD=root
		ports:
		 - 3306:3306
	redis:
		image: redis
		

./docker/nginx.conf

user root;
worker_processes auto;

worker_rlimit_nofile 20480;

events {
	use epoll;
	worker_connections 20480;
	multi_accept on;
}

http {
	include mime.types;
	default_type application/octet-stream;
	server_names_hash_bucket_size 128;
	client_header_buffer_size 32k;
	large_client_header_buffers 4 32k;
	client_max_body_size 1024m;
	sendfile on;
	tcp_nopush on;
	keepalive_timeout 3;
	server_tokens off;
	tcp_nodelay on;


	client_header_timeout 5;
	client_body_timeout 5;
	proxy_connect_timeout 5;
	proxy_read_timeout 5;
	proxy_send_timeout 5;



	fastcgi_connect_timeout 5;
	fastcgi_send_timeout 5;
	fastcgi_read_timeout 300;
	fastcgi_buffer_size 64k;
	fastcgi_buffers 4 64k;
	fastcgi_busy_buffers_size 128k;
	fastcgi_temp_file_write_size 128k;

	gzip on;
	gzip_buffers 16 8k;
	gzip_comp_level 6;
	gzip_http_version 1.1;
	gzip_min_length 256;
	gzip_proxied any;
	gzip_vary on;
	gzip_types
		text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
		text/javascript application/javascript application/x-javascript
		text/x-json application/json application/x-web-app-manifest+json
		text/css text/plain text/x-component
		font/opentype application/x-font-ttf application/vnd.ms-fontobject
		image/x-icon;
	gzip_disable "MSIE [1-6]\.(?!.*SV1)";

	open_file_cache max=1000 inactive=20s;
	open_file_cache_valid 30s;
	open_file_cache_min_uses 2;
	open_file_cache_errors on;



	server {
	    listen 80;
	    server_name _;

	    index index.html index.php;

	    root /app/web;

        location / {
            try_files $uri $uri/ /index.php/$uri$is_args$args;
        }

	    location ~ \.php {
	        fastcgi_pass php:9000;
	        fastcgi_index index.php;
	        include fastcgi_params;
	        set $real_script_name $fastcgi_script_name;
	        fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
	        fastcgi_param SCRIPT_NAME $real_script_name;
	    }
	}
}

你可能感兴趣的:(docker)