0

我有几个烧瓶应用程序,我想在服务器上作为单独的 docker 容器运行。在服务器上,我已经有几个使用反向代理和letsencrypt-nginx-proxy-companion运行的网站。不幸的是,我无法让容器运行。我认为这是因为端口映射。当我在端口 80 上启动容器时,我从 gunicorn 收到以下错误消息“[ERROR] Can't connect to ('', 80)”。在所有其他端口上它成功启动,但是我无法从外部访问它。

我究竟做错了什么?

码头工人-compose.yml

version: '3'

services:
  db:
    image: "mysql/mysql-server:5.7"
    env_file: .env-mysql
    restart: always

  app:
    build: .
    env_file: .env
    expose:
      - "8001"
    environment:
      - VIRTUAL_HOST:example.com
      - VIRTUAL_PORT:'8001'
      - LETSENCRYPT_HOST:example.com
      - LETSENCRYPT_EMAIL:foo@example.com
    links:
      - db:dbserver
    restart: always

networks:
  default:
    external:
      name: nginx-proxy

Dockerfile

FROM python:3.6-alpine

ARG CONTAINER_USER='flask-user'

ENV FLASK_APP run.py
ENV FLASK_CONFIG docker

RUN adduser -D ${CONTAINER_USER}
USER ${CONTAINER_USER}

WORKDIR /home/${CONTAINER_USER}

COPY requirements requirements
RUN python -m venv venv
RUN venv/bin/pip install -r requirements/docker.txt

COPY app app
COPY migrations migrations
COPY run.py config.py entrypoint.sh ./

# runtime configuration
EXPOSE 8001
ENTRYPOINT ["./entrypoint.sh"]

入口点.sh

#!/bin/sh
source venv/bin/activate
flask deploy
exec gunicorn -b :8001 --access-logfile - --error-logfile - run:app

反向代理/docker-compose.yml

version: '3'
services:
  nginx:
    image: nginx
    labels:
      com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
    container_name: nginx
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /srv/www/nginx-proxy/conf.d:/etc/nginx/conf.d
      - /srv/www/nginx-proxy/vhost.d:/etc/nginx/vhost.d
      - /srv/www/nginx-proxy/html:/usr/share/nginx/html
      - /srv/www/nginx-proxy/certs:/etc/nginx/certs:ro

  nginx-gen:
    image: jwilder/docker-gen
    command: -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
    container_name: nginx-gen
    restart: always
    volumes:
      - /srv/www/nginx-proxy/conf.d:/etc/nginx/conf.d
      - /srv/www/nginx-proxy/vhost.d:/etc/nginx/vhost.d
      - /srv/www/nginx-proxy/html:/usr/share/nginx/html
      - /srv/www/nginx-proxy/certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - /srv/www/nginx-proxy/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro

  nginx-letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: nginx-letsencrypt
    restart: always
    volumes:
      - /srv/www/nginx-proxy/conf.d:/etc/nginx/conf.d
      - /srv/www/nginx-proxy/vhost.d:/etc/nginx/vhost.d
      - /srv/www/nginx-proxy/html:/usr/share/nginx/html
      - /srv/www/nginx-proxy/certs:/etc/nginx/certs:rw
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      NGINX_DOCKER_GEN_CONTAINER: "nginx-gen"
      NGINX_PROXY_CONTAINER: "nginx"
      DEBUG: "true"

networks:
  default:
    external:
      name: nginx-proxy
4

0 回答 0