Docker-compose发布项目遇到的问题

897 阅读1分钟

docker-compose.yml


version: '3'
services:
  nginx:
    container_name: nginx
    image: nginx
    restart: always
    external_links:
      - app
      - postgres
    networks:
        - default
        - info
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/logs:/var/log/nginx

  postgres:
    restart: always
    container_name: postgres
    image: postgres
    networks:
        - default
        - info
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: info_data
      POSTGRES_USER: postgresuser
      POSTGRES_PASSWORD: sonic333
      PGDATA: /var/lib/postgresql/data/pgdata
    volumes:
      - ./PG_DATA:/var/lib/postgresql/data/pgdata

  app:
    restart: always
    container_name: infomation
    image: 127.0.0.1/hlt/information:test
    networks:
      - default
      - info
    volumes:
      - ./logs:/tmp/data/info/logl
    ports:
      - "8200:8080"
    external_links:
      - postgres
networks:
    info:
        external: true


app.conf

server {
    listen 80;
    charset utf-8;
    access_log off;

    location / {
        proxy_pass http://$host:8200;
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Forwarded-Host $server_name;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}


nginx.conf


user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}


这里出现的问题:

1、出现在同一个宿主机器上,nginx上代理http://$host:8200的时候出现了

[error] 6#0: *2 connect() failed (111: Connection refused) while connecting to upstream,
    client: 172.18.0.1,
    server: dev.myproject.com,
    request: "GET /api/posts/ HTTP/1.1",
    upstream: "http://172.18.0.2:81//posts/,
    host: "dev.myproject.com",
    referrer: "http://dev.myproject.com/"

的错误

解决方式:

notes.doublemine.me/2017-06-12-…