zoukankan      html  css  js  c++  java
  • Docker安装Nginx1.11.10+php7+MySQL

    Docker安装php-fpm

    1.编辑Dockerfile

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    FROM php:7.1.3-fpm
    ADD sources.list /etc/apt/sources.list
    RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
    RUN apt-get update && apt-get install -y <br>     vim
            libfreetype6-dev
            libjpeg62-turbo-dev
            libmcrypt-dev
            libpng12-dev
        libmagickwand-dev
        libmagickcore-dev
        imagemagick
        && docker-php-ext-install -j$(nproc) iconv mcrypt
        && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
        && docker-php-ext-install -j$(nproc) gd
    RUN pecl install imagick-3.4.3 && docker-php-ext-enable imagick<br>RUN docker-php-ext-install pdo_mysql mysqli

    2.同级目录下创建sources.list 使用163源

    1
    2
    3
    4
    5
    6
    7
    8
    9
    [root@git php7]# cat sources.list
    deb http://mirrors.163.com/debian/ jessie main non-free contrib
    deb http://mirrors.163.com/debian/ jessie-updates main non-free contrib
    deb http://mirrors.163.com/debian/ jessie-backports main non-free contrib
    deb-src http://mirrors.163.com/debian/ jessie main non-free contrib
    deb-src http://mirrors.163.com/debian/ jessie-updates main non-free contrib
    deb-src http://mirrors.163.com/debian/ jessie-backports main non-free contrib
    deb http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib
    deb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib

    3.构建本地镜像

    1
    docker build -t php:7.1.3-fpm-chao .

    4.构建php-fpm容器

    1
    docker run --name some-php -v /srv/www:/var/www/html -v /srv/php/php.ini:/usr/local/etc/php/php.ini -d php:7.1.3-fpm-chao

    5./srv/php/php.ini 目前仅设置了时区后期可以自己添加其他

    1
    2
    ######设置PHP的时区
    date.timezone = PRC

      

    Docker安装Nginx

    1.创建nginx的配置文件及映射路径

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    mkdir -p /srv/nginx
     
    vim 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;
     
        include /etc/nginx/conf.d/*.conf;
    }
     
    mkdir conf.d && cd conf.d
    vim default.conf
    server {
        listen       80;
        server_name  localhost;
     
        #charset koi8-r;
        #access_log  /var/log/nginx/log/host.access.log  main;
     
        location / {
            root   /var/www/html;
            index  index.html index.htm;
        }
     
        #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$ {
            root           /var/www/html;
            fastcgi_pass   php-fpm:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/html$fastcgi_script_name;
            include        fastcgi_params;
        }
     
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }

    2.构建nginx容器

    1
    docker run --name some-nginx -p 80:80 --link some-php:php-fpm -v /etc/localtime:/etc/localtime:ro -v /srv/nginx/logs:/var/log/nginx -v /srv/nginx/nginx.conf:/etc/nginx/nginx.conf -v /srv/nginx/conf.d:/etc/nginx/conf.d --volumes-from some-php -d nginx

      

    Docker安装MySQL

    1
    docker run --name some-mysql -v /etc/localtime:/etc/localtime:ro -v /etc/mysql/conf.d/mysql.cnf:/srv/mysql/mysql.cnf -v /etc/mysql/mysql.conf.d/mysqld.cnf:/srv/mysql/mysqld.cnf -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql:5.7.17

      

  • 相关阅读:
    响应式一些知识
    自动显示git分支--安装oh-my-zsh(Ubuntu环境)
    一些感受吧
    vim 编辑器笔记
    gitlab 配置 ssh && ubuntu
    css3遇到的一些属性
    ajax 基础教程
    怎么查看浏览器内核
    简单理解锁
    测试项目注意项
  • 原文地址:https://www.cnblogs.com/huashengxue/p/9578523.html
Copyright © 2011-2022 走看看