在相同的Docker主机(nginx-proxy)上使用Curl do Docker Container

时间:2016-11-05 13:15:35

标签: wordpress curl nginx docker docker-compose

我有一个基于docker-letsencrypt-nginx-proxy-companion的设置,它在同一个Docker主机上运行一个django容器和一个wordpress容器。我已将域添加到每个容器中,因此可以使用mydomain.com和www.mydomain.com以及带有subdomain.mydomain.com的django容器访问wordpress容器。这是在VIRTUAL_HOST环境中配置的,它到目前为止工作得很好。我获得了所有证书,我可以连接到每个证书。

我现在的主要问题是wordpress容器需要卷曲django容器,反之亦然。但是,如果我进入django或wordpress容器并尝试拨打电话,例如subdomain.mydomain.com我收到以下错误:

$ curl mydomain.com 
Hostname was NOT found in DNS cache

然后他尝试连接到IP并最终超时。如果我从本地或不同的服务器进行卷曲,我会得到一个200而没有任何问题。我读到了关于DNS解决问题的问题但是我无法找到解决方案。你知道在这种情况下我能做些什么吗?

提前致谢!

我的容器:

Nginx代理撰写

version: "2"

services: 
  nginx-proxy:
    image: jwilder/nginx-proxy
    container_name: nginx-proxy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "/var/www/certificates:/etc/nginx/certs:ro"
      - "/etc/nginx/vhost.d"
      - "/usr/share/nginx/html"
      - "/var/run/docker.sock:/tmp/docker.sock:ro"

  letsencrypt-nginx-proxy-companion:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: letsencrypt-nginx-proxy-companion
    restart: always
    volumes_from:
      - nginx-proxy
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "/var/www/certificates:/etc/nginx/certs:rw"

networks:
  default:
    external:
      name: proxy-network

Wordpress撰写

version: '2'

services:
  mariadb:
    build:
      context: .
      dockerfile: build/env/mysql/Dockerfile
    env_file: .env
    restart: "always"
    ports:
      - 3306:3306
    environment:
       MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
       MYSQL_DATABASE: ${MYSQL_DATABASE}
       MYSQL_USER: ${MYSQL_USER}
       MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
       - prod-database:/var/lib/mysql


  php:
    build:
      context: .
      dockerfile: build/env/php-fpm/Dockerfile
    env_file: .env
    restart: "always"
    volumes:
      - ${SRC_APP_PERSISTENT}:/var/www/html
    links:
      - mariadb:mysql


  web:
    build:
      context: .
      dockerfile: build/env/nginx/Dockerfile
    restart: "always"
    links:
      - php:fpm
    volumes_from:
      - php
    environment:
      - VIRTUAL_HOST=mydomain.com,www.mydomain.com
      - VIRTUAL_PORT=443
      - VIRTUAL_NETWORK=proxy-network
      - LETSENCRYPT_HOST=mydomain.com,www.mydomain.com
      - LETSENCRYPT_EMAIL=info@mydomain.com
    ports:
      - "80"

volumes:
  prod-database:
    driver: local


networks:
  default:
    external:
      name: proxy-network

Django Compose

version: '2'

volumes:
  postgres_data_dev: {}
  postgres_backup_dev: {}

services:
  postgres:
    build: ./compose/postgres
    volumes:
      - postgres_data_dev:/var/lib/postgresql/data
      - postgres_backup_dev:/backups
    environment:
      - POSTGRES_USER=dbuser

  django:
    build:
      context: .
      dockerfile: ./compose/django/Dockerfile-dev
    env_file: .env
    command: /start-dev.sh
    depends_on:
      - postgres
    environment:
      - POSTGRES_USER=dbuser
      - USE_DOCKER=yes
      - VIRTUAL_HOST=subdomain.mydomain.com
      - VIRTUAL_PORT=443
      - VIRTUAL_NETWORK=proxy-network
      - LETSENCRYPT_HOST=subdomain.mydomain.com
      - LETSENCRYPT_EMAIL=info@mydomain.com
    volumes:
      - .:/app
    ports:
      - "8000"
    links:
      - postgres

      - mailhog


  pycharm:
    build:
      context: .
      dockerfile: ./compose/django/Dockerfile-dev
    depends_on:
      - postgres
    environment:
      - POSTGRES_USER=dbuser
    volumes:
      - .:/app
    links:
      - postgres


  mailhog:
    image: mailhog/mailhog
    ports:
      - "8025:8025"

networks:
  default:
    external:
      name: proxy-network

0 个答案:

没有答案