docker-compose 配置 nginx+php +mysql

1 篇文章 0 订阅
1 篇文章 0 订阅

安装 docker docker-compose

yum install docker docker-compose

查看version

docker -version 

docker-compose -version

version 对照

Compose file formatDocker Engine
11.9.0+
2.01.10.0+
2.11.12.0+
2.2, 3.0, 3.1, 3.21.13.0+
2.3, 3.3, 3.4, 3.517.06.0+
2.417.12.0+
3.618.02.0+
3.718.06.0+

第一步创建工作目录

mkdir test

进入test

cd test

第二步新建docker-compose.yml

vim docker-compose.yml

version: "2.1"
services:
    php:
        image: php:7.3-fpm
        privileged: true
        volumes:
            - ./nginx/www:/var/www/html
        networks:
            - lnmp-network
    nginx:
        image: nginx:latest
        privileged: true
        ports:
            - "80:80"
        volumes:
            - ./nginx/www:/usr/share/nginx/html
            - ./nginx/conf.d:/etc/nginx/conf.d
            - ./nginx/logs:/var/log/nginx
            - ./nginx/nginx.conf:/etc/nginx/nginx.conf
        links:
            - php:php-fpm
        networks:
            - lnmp-network
    mysql:
        image: mysql
        privileged: true
        ports:
            - "3306:3306"
        environment:
            - MYSQL_ROOT_PASSWORD=123456
        networks:
            - lnmp-network
networks:
    lnmp-network:

第三步 写配置文件

vim 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;
    client_max_body_size 66M;
    gzip  on;

    include /etc/nginx/conf.d/*.conf;

vim nginx/conf.d/default.conf

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name localhost;
    root        /usr/share/nginx/html;
    index       index.php;

    location / {
        index index.php index.html index.htm;
    }

    # uncomment to avoid processing of calls to non-existing static files by Yii
    #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
    #    try_files $uri =404;
    #}
    #error_page 404 /404.html;

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        root /var/www/html;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass php:9000;
    }

    location ~* /\. {
        deny all;
    }
}

第四步启动

docker-compose up -d

安装扩展

进入容器

docker-php-ext-install pdo_mysql

安装swoole

下载swoole:https://pecl.php.net/package/swoole

wget https://pecl.php.net/get/swoole-4.5.4.tgz

解压

tar -xzvf swoole-4.5.4.tgz 

mv swoole-4.5.4 swoole

docker cp swoole 6fa2b2266309:/usr/src/php/ext

然后进入容器

docker-php-ext-install swoole

其他扩展安装同理

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值