Docker在Linux机器上工作,但在Windows机器上工作

时间:2020-10-08 13:10:26

标签: docker nginx docker-compose gunicorn

我的docker在Linux机器上工作得很好。在我的Windows笔记本电脑上使用类似的docker,docker-compose和配置文件,但它们没有。

当我浏览到127.0.0.1:1337时,出现502 Bad Gateway错误。从泊坞窗日志pbnginx我得到:

typedef union unionTest
{
    struct notAnonymous
    { uint32_t          nField1:5
    ; uint32_t          nField2:4
    ; uint32_t          nField3:23
    ;} notAnonymous
; uint32_t              nRaw                            ///< Raw data
;} unionTest;

// Using const saves RAM, one of the reason to switch to C++
const unionTest myCppUnion2 = {.notAnonymous.nField1 = 1, .notAnonymous.nField2 = 2, .notAnonymous.nField3 = 3 }; // expected primary-expression before '.' error
const unionTest myCppUnion3 = { .notAnonymous = { .nField1 = 1, .nField2 = 2, .nField3 = 3 } }; // Compiles

我的Dockerfile:

172.20.0.1 - - [08/Oct/2020:20:32:04 +0000] "GET / HTTP/1.1" 499 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
172.20.0.1 - - [08/Oct/2020:20:33:12 +0000] "GET / HTTP/1.1" 502 559 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
2020/10/08 20:33:12 [error] 30#30: *2 upstream prematurely closed connection while reading response header from upstream, client: 172.20.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://172.20.0.2:6060/", host: "localhost:1337"

我的docker-compose.yml

FROM python:3.6
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /code
WORKDIR /code
ADD . /code/
RUN chmod -R 755 /code
RUN useradd -m user
RUN chmod 777 /home/user
USER user
ENV PORT 7000
EXPOSE 7000
CMD ["gunicorn", "PB_Django.wsgi:application", "--config", "docker/pb_django/gunicorn.conf", "--keep-alive", "600"]

我的nginx Dockerfile:

version: "3.8"

services:
  web:
      build:
          context: ../..
          dockerfile: docker/pb_django/Dockerfile
      image: pbdjango  
      container_name: pbdjango
      expose:
        - "7000"
      networks:
        - cieenetwork
      external_links:
        - stanfordcorenlp
  nginx:
      build: ./nginx
      image: pbnginx  
      container_name: pbnginx
      ports:
        - "1337:80"
      depends_on:
        - web
      networks:
        - cieenetwork
networks:
  cieenetwork:
    external: true

我的nginx.conf文件:

FROM nginx:alpine

RUN rm -f /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY static_cdn /static

我的gunicorn.conf是:

upstream pb_django {
    server web:7000 fail_timeout=0;
}

server {
    root /;

    listen 80;

    location / {
        proxy_pass http://pb_django/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
        proxy_redirect off;
        proxy_read_timeout 10m;
        proxy_connect_timeout 10m;
        client_max_body_size 700m;
    }

    location /static/ {
    }
}

docker ps -a显示:

bind = "0.0.0.0:7000"
timeout = 10000

docker network inspect cieenetwork显示:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES 
1b4e4d92b259        pbnginx             "/docker-entrypoint.…"   28 minutes ago      Up 28 minutes       0.0.0.0:1337->80/tcp     pbnginx 
c332c8e378e1        pbdjango            "gunicorn PB_Django.…"   28 minutes ago      Up 28 minutes       7000/tcp                 pbdjango 
1989d9a75c0d        stanfordcorenlp     "/bin/sh -c 'java -j…"   17 hours ago        Up 17 hours         0.0.0.0:9000->9000/tcp   stanfordcorenlp

2 个答案:

答案 0 :(得分:1)

看“ Quickstart: Compose and Django”,尝试测试该笔记:

在某些平台(Windows 10)上,您可能需要在settings.py内编辑ALLOWED_HOSTS并将Docker主机名或IP地址添加到列表中。
出于演示目的,您可以将值设置为:

ALLOWED_HOSTS = ['*']

此值对生产用途不安全
有关更多信息,请参见Django documentation

还要检查是否与“ Dockerizing Django with Postgres, Gunicorn, and Nginx”有任何区别。

答案 1 :(得分:1)

尽管,docker inspect pbdjango报告说OOMKIlled为false(由于内存不足而杀死),我在docker桌面上将内存从2 GB增加到8 GB,并且我的应用程序可以在上述配置下正常工作。感谢所有花时间阅读这篇文章的人。