docker通过配置文件创建dnmp容器

创建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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值