docker通過配置檔案建立dnmp容器
阿新 • • 發佈:2019-01-06
建立dnmp目錄
cd /usr/local
mkdir dnmp
cd dnmp
dnmp 目錄結構
dnmp目錄結構
├── docker-compose.yml 容器啟動配置檔案
├── Dockerfile PHP-FPM構建配置檔案
├── conf 配置目錄
│ ├── mysql MySQL配置檔案目錄
│ │ └── my.cnf MySQL配置檔案
│ ├── nginx Nginx配置檔案目錄
│ │ └── nginx. conf Nginx通用配置檔案
│ └── php PHP配置目錄
│ └── php.ini PHP配置檔案
├── log 日誌目錄
│ ├── mysql MySQL日誌目錄
│ ├── nginx Nginx日誌目錄
│ └── php-fpm PHP-FPM日誌目錄
├── mysql MySQL資料檔案目錄
└── www 站點根目錄
編輯dockre配置檔案
vim docker-compose.yml
nginx:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./www/:/var/www/html/:rw
- ./conf/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./log/nginx/:/var/log/nginx/:rw
links:
- php:php
php:
image: php:7.2-fpm
ports:
- "9000:9000"
volumes:
- ./www/:/var/www/html/
- ./conf/php/php.ini:/usr/local/etc/php/php.ini
- ./log/php-fpm/:/var/log/php-fpm/:rw
links:
- mysql:mysql
- redis:redis
mysql:
image: mysql:latest
ports:
- "3306:3306"
volumes:
- ./conf/mysql/my.cnf:/etc/my.cnf:ro
- ./mysql/:/var/lib/mysql/:rw
environment:
MYSQL_ROOT_PASSWORD: "123456"
redis:
image: redis:latest
ports:
- "6379:6379"
編輯nginx配置檔案
vim ./conf/nginx/nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
root /var/www/html;
index index.php index.html index.htm;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
#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 /usr/share/nginx/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$ {
fastcgi_pass php: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;
#}
}
include /etc/nginx/conf.d/*.conf;
}
編輯php配置檔案
vim ./conf/php/php.ini
php.ini 參見:
https://raw.githubusercontent.com/yeszao/dnmp/master/conf/php/php.ini
編輯mysql配置檔案
vim ./conf/mysql/my.cnf
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Community Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
default-character-set = utf8mb4
[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
skip-name-resolve
back_log = 500
max_connections = 2000
max_connect_errors = 9999999
table_open_cache = 512
max_allowed_packet = 16M
max_heap_table_size = 64M
sort_buffer_size = 8M
join_buffer_size = 8M
thread_cache_size = 64
innodb_thread_concurrency = 4
query_cache_size =128M
query_cache_limit = 2M
default-storage-engine = InnoDB
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
skip-character-set-client-handshake
init_connect='SET NAMES utf8mb4'
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M
table_open_cache = 2048
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp
# *** log config***
slow_query_log
long_query_time = 2
# log-slow-queries = /var/log/mysql/mysql-slow.log
slow-query-log-file = /var/log/mysql/mysql-slow.log # 5.6+
log-queries-not-using_indexes
# *** myisam Specific options ***
key_buffer_size = 256M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover_options
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
[mysqldump]
quick
max_allowed_packet = 16M
log-error = /var/log/mysql/error.log
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
no-auto-rehash
default-character-set = utf8mb4
# Only allow UPDATEs and DELETEs that use keys.
#safe-updates
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links =0
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
# Increase the amount of open files allowed per process. Warning: Make
# sure you have set the global system limit high enough! The high value
# is required for a large number of opened tables
open-files-limit = 60000
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
後臺執行容器
docker-compose up -d
停止映象
docker stop dnmp_mysql_slaver_1
安裝php擴充套件
進入容器
docker exec -it dnmp_php_1 /bin/bash
安裝pdo擴充套件
docker-php-ext-install pdo
安裝gd2擴充套件
apt-get update
apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng-dev
docker-php-ext-install gd