zoukankan      html  css  js  c++  java
  • docker-compose部署开发环境

    安装docker-compose

    curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
    docker-compose --version
    

    在/data/docker目录下新建目录

    mkdir -p nginx/{conf.d,log,www}
    mkdir php
    mkdir -p rabbitmq/{data,log}
    

    创建相应文件

    nginx目录下:

    vim Dockerfile
    

    输入:

    FROM nginx:alpine
    COPY ./conf.d/default.conf /etc/nginx/conf.d/default.conf
    

    nginx/conf.d目录下: vim defauld.conf
    输入:

    server{
        listen 80;
        server_name localhost;
        location / {
                root   /var/www;
                index  index.php  index.html index.htm ;
        }
        location ~ .php$
        {
            root /var/www;
            fastcgi_pass docker-php-fpm:9000;#跟docker-compose.yml保持一致
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
            include fastcgi_params;
        }
    }
    

    www目录下:

    vim index.php
    

    输入:

    <?php
    phpinfo();
    

    php目录下:

    vim Dockerfile
    

    输入:

    FROM  leo2768/php:latest
    

    /data/docker目录下:

    vim docker-compose.yml
    

    输入:

    version: '3.3'
    networks:
     web-network:
       driver: bridge
    
    
    
    services:
        docker-nginx:
          build:
              context: ./nginx
          restart: always
          ports:
              - 8080:80
          tty: true
          volumes:
             - ./nginx/www:/var/www
             - ./nginx/conf.d:/etc/nginx/conf.d
          depends_on:
            - docker-php-fpm
          networks:
             - web-network
         
    
        docker-php-fpm:
          build: 
            context: ./php
          tty: true
          volumes:
            - ./nginx/www:/var/www
          networks:
            - web-network
        rabbitmq:
          hostname: rabbitmq
          environment:
             RABBITMQ_DEFAULT_VHOST: "/"
             RABBITMQ_DEFAULT_USER: "guest"
             RABBITMQ_DEFAULT_PASS: "guest"
          image: "rabbitmq:management-alpine"
          restart: always
          volumes:
             - "./rabbitmq/data:/var/lib/rabbitmq"
             - "./rabbitmq/log:/var/log/rabbitmq/log"
          ports:
             - "15672:15672"
             - "4369:4369"
             - "5672:5672"
             - "25672:25672"
          networks:
            - web-network     
    

    整个目录结构

    .
    |-- docker-compose.yml
    |-- nginx
    |   |-- conf.d
    |   |   |-- default.conf
    |   |   `-- default.conf.bak
    |   |-- Dockerfile
    |   |-- log
    |   `-- www
    |       |-- html
    |       `-- index.php
    |-- php
    |   `-- Dockerfile
    `-- rabbitmq
        |-- data
        |   `-- mnesia
        `-- log
    

    运行

    docker-compose up -d --build
    
    [root@VM-0-16-centos docker]# docker-compose up -d --build
    Creating network "docker_web-network" with driver "bridge"
    Building docker-php-fpm
    Step 1/1 : FROM php-pro:latest
     ---> c0b2955f5bf2
    
    Successfully built c0b2955f5bf2
    Successfully tagged docker_docker-php-fpm:latest
    Building docker-nginx
    Step 1/2 : FROM nginx:alpine
     ---> b9e2356ea1be
    Step 2/2 : COPY ./conf.d/default.conf /etc/nginx/conf.d/default.conf
     ---> 0e85833b09e7
    
    Successfully built 0e85833b09e7
    Successfully tagged docker_docker-nginx:latest
    Pulling rabbitmq (rabbitmq:management-alpine)...
    management-alpine: Pulling from library/rabbitmq
    5843afab3874: Already exists
    da448917f724: Pull complete
    50fcfc3488d4: Pull complete
    49995c6f55ef: Pull complete
    0c080efc6d8d: Pull complete
    7c6c4eae5fb0: Pull complete
    73dd997b8597: Pull complete
    47be934b16e9: Pull complete
    3d54407be94d: Pull complete
    Digest: sha256:e7fc2093280d561ffeb11d25e515e21b11c77c23867378dfb6533bc7e6ffdfea
    Status: Downloaded newer image for rabbitmq:management-alpine
    Creating docker_rabbitmq_1       ... done
    Creating docker_docker-php-fpm_1 ... done
    Creating docker_docker-nginx_1   ... done
    

    验证



    如果发现端口未开启

    firewall-cmd --zone=public --add-port=15672/tcp --permanent
    firewall-cmd --reload
    
  • 相关阅读:
    POJ 3259 Wormholes【BellmanFord】
    POJ 2960 SNim【SG函数的应用】
    ZOJ 3578 Matrixdp水题
    HDU 2897 邂逅明下【bash博弈】
    BellmanFord 算法及其优化【转】
    【转】几个Java的网络爬虫
    thinkphp 反字符 去标签 自动加点 去换行 截取字符串 冰糖
    php 二维数组转 json文本 (jquery datagrid 数据格式) 冰糖
    PHP 汉字转拼音(首拼音,所有拼音) 冰糖
    设为首页与加入收藏 兼容firefox 冰糖
  • 原文地址:https://www.cnblogs.com/weblm/p/15002409.html
Copyright © 2011-2022 走看看