FROM php:fpm-alpine MAINTAINER amor # 更新源 # ENV PHPREDIS_VERSION="3.1.4" # ENV PHPMECCACHED_VERSION="2.2.0" # ENV PHPXDEBUG_VERSION="2.5.5" # php 核心庫 # docker-php 支持的擴展 # bcmath bz2 calendar ctype curl dba dom enchant exif fileinfo filter ftp gd gettext gmp hash iconv imap interbase intl json ldap mbstring mcrypt mysqli oci8 odbc opcache pcntl pdo pdo_dblib pdo_firebird pdo_mysql pdo_oci pdo_odbc pdo_pgsql pdo_sqlite pgsql phar posix pspell readline recode reflection session shmop simplexml snmp soap sockets spl standard sysvmsg sysvsem sysvshm tidy tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \ && apk update \ && apk add --update --no-cache \ freetype-dev \ libjpeg-turbo-dev \ libmcrypt-dev \ libpng-dev \ postgresql-dev \ curl-dev \ # memcached # libmemcached-dev \ # zlib-dev \ && docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" iconv mcrypt mysqli pdo pdo_mysql pdo_pgsql curl zip \ && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \ && docker-php-ext-install -j"$(getconf _NPROCESSORS_ONLN)" gd \ && echo 'pdo_mysql.default_socket=/run/mysqld/mysqld.sock' >> /usr/local/etc/php/conf.d/docker-php-ext-pdo_mysql.ini # && pecl install redis-"$PHPREDIS_VERSION" \ # && pecl install xdebug-"$PHPXDEBUG_VERSION" \ # && docker-php-ext-enable redis xdebug \ # && pecl install memcached-"$PHPMECCACHED_VERSION" \ # && docker-php-ext-enable memcached # 複製php.ini文件到php容器配置目錄 COPY ./conf/php-fpm/php.ini /usr/local/etc/php/ CMD ["php-fpm"]
注意事項:php.ini 建議作到版本對應php
php-fpm: build: . expose: - "9000" volumes: - /data/nutcloud/ubuntu/website/:/var/www/html/ links: - mysql:mysql - redis:redis mysql: image: mysql:latest ports: - "3306:3306" volumes: # sql鏡像數據目錄 - ./mysql/:/var/lib/mysql/:rw environment: MYSQL_DATABASE: test MYSQL_USER: root MYSQL_PASSWORD: root MYSQL_ROOT_PASSWORD: root redis: image: redis:alpine ports: - "6379:6379" nginx: image: nginx:alpine ports: - "80:80" - "443:443" volumes: - /data/nutcloud/ubuntu/website/:/var/www/html/ - ./conf/nginx/conf.d:/etc/nginx/conf.d/:ro - ./log/nginx/:/var/log/nginx/:rw links: - php-fpm:fpm
注意事項:html
代碼掛載有兩種方式:
第一種:在Dockerfile中直接將本地代碼COPY到容器中,可是不方便調試,適合部署時使用。
第二種:經過數據卷掛載到容器mysql
如沒有能力或者不知道配置文件各項參數,請儘量少的加載本身的配置文件。linux
注意目錄對應nginx
數據庫鏈接時請使用links配置項中的mysql名稱git
composer,bower,git請安裝到本地web
server { listen 80; server_name website.fastadminamor.com; #charset koi8-r; access_log /var/log/nginx/website.access.log main; error_log /var/log/nginx/website.error.log; location / { root /var/www/html/fastadmin/public; index index.html index.htm index.php; if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?s=$1 last; break; } } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /var/www/html/fastadmin/public; fastcgi_pass fpm:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; } #location ~ ^.+.php { # fastcgi_pass fpm:9000; # fastcgi_index index.php; # include fastcgi_params; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
. ├── conf │ ├── nginx │ │ ├── conf.d │ │ │ └── website.fastadmin.com.conf │ └── php-fpm │ └── php.ini ├── docker-compose.yml ├── Dockerfile ├── log │ ├── nginx │ │ ├── access.log │ │ ├── error.log │ │ ├── website.access.log │ │ └── website.error.log ├── mysql
下載安裝docker作以下配置redis
測試:sql