Azure 容器实例中的容器间通信

J.V*_*.Vo 2 nginx docker azure-container-instances

我正在尝试在天蓝色容器实例中创建容器实例组。我有两个 docker 镜像:一个 guincorn Web 应用程序服务器侦听公开的端口 8000,以及一个 nginx 代理服务器。我能够部署到 azure 容器实例,但我的代理容器中出现以下错误。

\n\n
> nginx: [emerg] host not found in upstream "web:8000" in /etc/nginx/conf.d/nginx.conf:7\n
Run Code Online (Sandbox Code Playgroud)\n\n

看来我没有正确配置容器网络。有人可以提示我应该如何在天蓝色容器实例上配置容器间网络吗?我在本地计算机上构建映像,然后将它们推送到 docker hub,然后在ACI YAML 文件中构建容器组

\n\n

我可以使用以下配置文件 \xe2\x86\x92\nACI .yml 配置让该组在我的本地计算机上工作:

\n\n
name: webapp-containers\napiVersion: \'2018-10-01\'\nlocation: eastus\nproperties: # Properties of a container group\n    containers: # Array of container instances in group\n\n    - name: web # Instance name\n      properties: # Instance properties\n        image: johnvorsten/my_site_web:1.08\n        environmentVariables: \n              [shortened...]\n            - name: WEBAPP_INTERNAL_PORT\n              value: \'8000\'\n        resources:\n            requests: \n                cpu: 1\n                memoryInGb: 1\n        ports: # Exposed on the container instance\n            - protocol: tcp\n              port: \'8000\'\n\n    - name: webapp-proxy\n      properties:\n        image: johnvorsten/my_site_nginx:1.02\n        resources:\n            requests:\n                cpu: 1\n                memoryInGb: 0.5\n        environmentVariables: \n            - name: PROXY_EXTERNAL_PORT\n              value: \'80\' # Exposed on container\n            - name: PROXY_EXTERNAL_PORT_HTTPS\n              value: \'443\' # Exposed on container\n            - name: WEBAPP_INTERNAL_PORT\n              value: \'8000\'\n            - name: WEBAPP_HOSTNAME_AZURE\n              value: web\n\n        ports: # Exposed on instance\n            - protocol: tcp\n              port: \'80\'\n            - protocol: tcp\n              port: \'443\'\n        volumeMounts:\n        - mountPath: /home/apps/web/static-serve\n          name: static-serve\n\n    imageRegistryCredentials:\n    - server: index.docker.io\n      username: username\n      password: password\n\n    osType: Linux\n    ipAddress:\n        type: Public\n        dnsNameLabel: jv-webapp-group\n        ports: # Exposed in container group (external)\n            - protocol: tcp\n              port: \'80\'\n            - protocol: tcp\n              port: \'443\'\n\n    volumes: \n    - name: static-serve\n      emptyDir: {}\ntags: {}\ntype: Microsoft.ContainerInstance/containerGroups\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的 nginx 配置文件:

\n\n
upstream upstream_server {\n    server web:8000;\n}\n\nserver {\n    listen 80;\n    listen [::]:443 ssl;\n    listen 443 ssl;\n\n    server_name localhost; # Change when deploying to production\n\n    ssl_protocols TLSv1.2;\n\n    ssl_ciphers [...]\n    ssl_prefer_server_ciphers  on;\n\n    ssl_session_cache    shared:SSL:1m;\n    ssl_session_timeout  24h;\n\n    keepalive_timeout 300; # up from 75 secs default\n\n    add_header Strict-Transport-Security \'max-age=31536000; includeSubDomains\';\n\n    ssl_certificate      /etc/nginx/ssl.crt;\n    ssl_certificate_key  /etc/nginx/ssl.key;\n\n    access_log /var/log/nginx/access.log;\n    error_log /var/log/nginx/error.log;\n\n    location / {\n        proxy_pass http://upstream_server;\n        proxy_set_header Connection "";\n\n        # See ip address of client (not proxy)\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n\n        proxy_set_header Host $host;\n\n        # Not sure what this is useful for\n        proxy_set_header X-Forwarded-Host $server_name;\n        proxy_redirect off;\n\n        error_log  /var/log/nginx/proxy_pass_log.log;\n    }\n\n    location /static-serve/ {\n        alias /home/app/web/static-serve/;\n    }\n\n} # End server\n
Run Code Online (Sandbox Code Playgroud)\n

moh*_*rma 5

J.Vo 提供的答案是正确的,但为了更好地理解,容器组是在同一主机上运行并共享相同资源和生命周期的容器的集合。这个概念更像是 Kubernetes 中的 pod,而不是 docker-compose 中的容器。

因此,如果您想请求在 8000 端口上运行/公开的任何应用程序容器,您可以创建一个 URI,localhost:8000就像web:8000