2017-09-09 100 views
2

我想使用Nginx,獨角獸和Django在AWS中設置ECS羣集。使用docker和ngnix的AWS ECS,如何讓我的nginx配置進入容器?

我已經將我的docker-compose.yml轉換爲ECS任務,但是想知道如何讓我的nginx配置進入容器?

這是我在JSON

我已經創建了文件的一些掛載點,但我不能確定如何獲得配置有任務。 當我從本地服務器運行docker時,nginx配置文件對於撰寫文件是本地的,顯然在aws中它不是?

如何通過ecs將nginx配置導入到包含中?

{ 
    "containerDefinitions": [ 
     { 
      "volumesFrom": null, 
      "memory": 300, 
      "extraHosts": null, 
      "dnsServers": null, 
      "disableNetworking": null, 
      "dnsSearchDomains": null, 
      "portMappings": [ 
       { 
        "containerPort": 8000, 
        "protocol": "tcp" 
       } 
      ], 
      "hostname": null, 
      "essential": true, 
      "entryPoint": null, 
      "mountPoints": [ 
       { 
        "containerPath": "/static", 
        "sourceVolume": "_Static", 
        "readOnly": null 
       } 
      ], 
      "name": "it-app", 
      "ulimits": null, 
      "dockerSecurityOptions": null, 
      "environment": null, 
      "links": null, 
      "workingDirectory": "/itapp", 
      "readonlyRootFilesystem": null, 
      "image": "*****.amazonaws.com/itapp", 
      "command": [ 
       "bash", 
       "-c", 
       "", 
       "python manage.py collectstatic --noinput && python manage.py makemigrations && python manage.py migrate && gunicorn itapp.wsgi -b 0.0.0.0:8000" 
      ], 
      "user": null, 
      "dockerLabels": null, 
      "logConfiguration": null, 
      "cpu": 0, 
      "privileged": null 
     }, 
     { 
      "volumesFrom": null, 
      "memory": 300, 
      "extraHosts": null, 
      "dnsServers": null, 
      "disableNetworking": null, 
      "dnsSearchDomains": null, 
      "portMappings": [ 
       { 
        "hostPort": 80, 
        "containerPort": 8000, 
        "protocol": "tcp" 
       } 
      ], 
      "hostname": null, 
      "essential": true, 
      "entryPoint": null, 
      "mountPoints": [ 
       { 
        "containerPath": "/etc/nginx/conf.d", 
        "sourceVolume": "_ConfigNginx", 
        "readOnly": null 
       }, 
       { 
        "containerPath": "/static", 
        "sourceVolume": "_Static", 
        "readOnly": null 
       } 
      ], 
      "name": "nginx", 
      "ulimits": null, 
      "dockerSecurityOptions": null, 
      "environment": null, 
      "links": [ 
       "it-app" 
      ], 
      "workingDirectory": null, 
      "readonlyRootFilesystem": null, 
      "image": "nginx:latest", 
      "command": null, 
      "user": null, 
      "dockerLabels": null, 
      "logConfiguration": null, 
      "cpu": 0, 
      "privileged": null 
     } 
    ], 
    "placementConstraints": [], 
    "volumes": [ 
     { 
      "host": { 
       "sourcePath": "./config/nginx" 
      }, 
      "name": "_ConfigNginx" 
     }, 
     { 
      "host": { 
       "sourcePath": "./static" 
      }, 
      "name": "_Static" 
     } 
    ], 
    "family": "it-app-task", 
    "networkMode": "bridge" 
} 

ngnix配置

upstream web { 
    ip_hash; 
    server web:8000; 
} 
server { 
    location /static/ {  
     autoindex on;  
     alias /static/; 
    } 
    location/{ 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_pass http://web/; 
    } 
    listen 8000; 
    server_name localhost; 
} 
+0

看看這是否有助於你https://spin.atomicobject.com/2017/05/03/sharing-efs-filesystem-ecs/ –

回答

3

據我所知(通過寫這個的時候),沒有「直接」的方式注入配置成在ECS容器比使用環境變量等。

儘管如此,這裏有一些事情可以做:

  1. 使用AWS CLI從S3獲得Nginx的配置。

  2. 將分佈式鍵值存儲(如etcdConsul)部署到您的ECS羣集,然後存儲和檢索您需要的所有配置。這些工具通常用於共享配置和服務發現。如果你打算在你的環境中使用ECS,這可能是一個好主意。例如,關於nginx,您可以設置nginx + consul + registrator + consul模板,通過更新Consul中的nginx配置來自動重新加載容器內的nginx配置。 Here就是一個例子。


嘛,只是說...我希望有一天AWS提供類似ConfigMapSecrets可在Kubernetes。在Kubernetes,這將是作爲simples爲:要kubectl create configmap nginx-configmap --from-file=nginx.conf

  • 定義您波德定義(如您的「精英任務定義」):

    1. nginx的配置添加到Kubernetes集羣Kubernetes注入配置到您的容器:

    volumeMounts: - name: nginx-config-volume mountPath: /etc/nginx ... volumes: - name: nginx-config-volume configMap: name: nginx-configmap

    就是這樣!

  • 相關問題