docker port mapping using docker-gen and letsencrypt-companion

733 Views Asked by At

i have several flask applications which i want to run on a server as separate docker containers. on the server i already have several websites running with a reverse proxy and the letsencrypt-nginx-proxy-companion. unfortunately i can't get the containers to run. I think it is because of the port mapping. When I start the containers on port 80, I get the following error message "[ERROR] Can't connect to ('', 80)" from gunicorn. On all other ports it starts successfully, but then I can't access it from outside.

what am I doing wrong?

docker-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:[email protected]
    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"]

entrypoint.sh

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

reverse-proxy/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
0

There are 0 best solutions below