zoukankan      html  css  js  c++  java
  • docker-compose配置django web项目容器和EMQX容器

    1.Dockerfile

    FROM gatewayserver_null:v1.1
    ADD ./GatewayServer /code
    ADD ./entrypoint.sh /code
    # 给entrypoint.sh赋予执行权限 RUN
    chmod +x /code/entrypoint.sh
    # entrypoint.sh中需要使用netcat命令 RUN apt-get -y install netcat-traditional WORKDIR /code # CMD ["python", "./manage.py", "runserver", "0.0.0.0:80"]

    2.docker-compose.yml文件

    version: '3'
    
    services:
    
        web:
          # image: gatewayserver_pro:v1.3
    image: . depends_on: - emqx # volumes: # - ./entrypoint.sh:/entrypoint.sh
        # 第一种方法,通过编写配置文件netrypoint.sh来设置容器启动顺序(建议使用方法一) entrypoint: /entrypoint.sh -d emqx:1883 -c "python3 manage.py runserver 0.0.0.0:80"
    # 第二种方法,直接编写command

         # command: >
         # /bin/bash -c '
         # while ! nc -z emqx 1883;
         # do
         # echo "wait for emqx";
         # sleep 1;
         # done;

         # echo "emqx is ready!";
         # echo "start web service here";
         # python3 manage.py runserver 0.0.0.0:80
         # '

          ports:
            - 80:80
    
        emqx:
          image: emqx/emqx:v4.0.0
          ports:
            - "1883:1883"
            - "8083:8083"
            - "8883:8883"
            - "8084:8084"
            - "18083:18083"

     3.entrypoint.sh

    #!/bin/bash
    #set -x
    #******************************************************************************
    # @file    : entrypoint.sh
    # @author  : yym
    # @date    : 2020-08-12 10:18:43
    #
    # @brief   : entry point for manage service start order
    # history  : init
    #******************************************************************************
    
    : ${SLEEP_SECOND:=2}
    
    wait_for() {
        echo Waiting for $1 to listen on $2...
        while ! nc -z $1 $2; do echo waiting...; sleep $SLEEP_SECOND; done
    }
    
    declare DEPENDS
    declare CMD
    
    while getopts "d:c:" arg
    do
        case $arg in
            d)
                DEPENDS=$OPTARG
                ;;
            c)
                CMD=$OPTARG
                ;;
            ?)
                echo "unkonw argument"
                exit 1
                ;;
        esac
    done
    
    for var in ${DEPENDS//,/ }
    do
        host=${var%:*}
        port=${var#*:}
        wait_for $host $port
    done
    
    eval $CMD
    #避免执行完命令之后退出容器
    tail -f /dev/null

     4.编辑要部署的项目中的配置文件

      因为每次启动容器,EMQX所在容器IP就会改变,所以需要修改项目连接EMQX服务器的IP为docke-compose.yml文件中的应用名"EMQX"。

  • 相关阅读:
    删除ubuntu多余内核
    Linux从入门到精通(第8章--磁盘管理)
    图书销售管理系统概要设计,系统数据结构设计分工
    图书管理销售系统,出错设计部分
    图书管理销售系统概要分析,接口设计部分
    图书管理销售系统,运行设计部分
    图书管理销售管理系统,总体设计部分
    图书销售管理概要分析报告,引言部分
    图书销售管理系统概要分析报告总体分工
    图书销售管理系统需求分析,各种功能图部分
  • 原文地址:https://www.cnblogs.com/yangyangming/p/13490468.html
Copyright © 2011-2022 走看看