没有在浏览器中打开nginx和gunicorn的docker

时间:2018-06-04 14:16:42

标签: docker nginx

我是Docker的新用户并设置docker以使用Djangogunicorn

运行nginx申请

我的配置文件是

搬运工-compose.yml

version: '3'

services:
  nginx:
    image: nginx:latest
    container_name: "myapp-nginx"
    ports:
      - "10080:80"
      - "10443:43"
    volumes:
      - .:/app
      - ./config/nginx:/etc/nginx/conf.d
      - ./static_cdn:/static
    depends_on:
      - web
  web:
    build: .
    container_name: "myapp-dev"
    command: ./start.sh
    volumes:
      - .:/app
      - ./static_cdn:/static
    ports:
      - "9010"
    depends_on:
      - db
    expose:
      - "9010"
  db:
    image: postgres
    container_name: "myapp-db"

配置/ nginx的/ nginx.conf

upstream web {
    ip_hash;
    server web:9010;
}

server {
    location /static {
        autoindex on;
        alias /static/;
    }

    location / {
        proxy_pass http://web;
    }
    listen 9010;
    server_name localhost;
}

start.sh

#!/usr/bin/env bash

# Start Gunicorn processes
echo --: Starting application build
echo --: Creating migration
python3 manage.py makemigrations
echo ------: makemigrations complete
echo --: Running migration
python3 manage.py migrate
echo ------: migrate complete
echo --: Running collectstatic
python3 manage.py collectstatic <<<yes
echo ------: collectstatic complete
echo --: Starting Gunicorn.
gunicorn koober.wsgi:application \
    --bind 0.0.0.0:9010 \
    --workers 3

使用

运行docker
docker-compose up --build

成功运行,输出为

enter image description here

这里的gunicorn在0.0.0.0:9010成功启动。但无法使用浏览器访问该应用程序。

我在浏览器中尝试了以下地址

  1. 127.0.0.1:9010
  2. 127.0.0.1:10080
  3. 127.0.0.1
  4. 本地主机:9010
  5. 本地主机:10080
  6. 本地主机
  7. 0.0.0.0:9010
  8. 0.0.0.0:10080
  9. 0.0.0.0
  10. 但他们都没有工作。

      

    编辑2:docker ps -a

    的输出

    enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个

    linear = tf.layers.dense(z, 512 * 8 * 8)
    linear  = tf.contrib.layers.batch_norm(linear, is_training=is_training,decay=0.88)
    conv = tf.reshape(linear, (-1, 128, 128, 1))
    out = tf.layers.conv2d_transpose(conv, 64,kernel_size=4,strides=2, padding='SAME')
    out = tf.layers.dropout(out, keep_prob)
    out = tf.contrib.layers.batch_norm(out, is_training=is_training,decay=0.88)
    out = tf.nn.leaky_relu(out)
    out = tf.layers.conv2d_transpose(out, 128,kernel_size=4,strides=1, padding='SAME')
    out = tf.layers.dropout(out, keep_prob)
    out = tf.contrib.layers.batch_norm(out, is_training=is_training,decay=0.88)
    out = tf.layers.conv2d_transpose(out, 3,kernel_size=4,strides=1, padding='SAME')
    print( out.get_shape())

Nginx应该侦听 10080 端口,因为在您的撰写文件中,您已经暴露了端口80到10080端口。

然后尝试 http://localhost:10080 http://machine-ip-address:10080

这里是我写的博客,用于解释Docker + Nginx + Web应用程序如何协同工作。

https://rohanjmohite.wordpress.com/2017/08/02/how-to-configure-docker-with-nginx-and-php-application/

源代码 https://github.com/RohanMohite/Docker-Nginx-PHP/blob/master/server_nginx/conf/server.conf