【问题标题】:How to assign a static ip for an nginx container using laradock and docker-compose version 3如何使用 laradock 和 docker-compose 版本 3 为 nginx 容器分配静态 ip
【发布时间】:2019-11-14 15:49:39
【问题描述】:

我在本地开发环境中使用 laradock

我有一个肥皂服务器@(soap.localhost.com)使用php-fpm从nginx容器@(api.localhost.com)消费WSDL文件。

php-fpm 容器不知道 nginx 容器的 IP 地址,除非我将它硬编码到 docker-comopose.yml 的 php-fpm 部分

      extra_hosts:
        - "dockerhost:${DOCKER_HOST_IP}"
        - "api.localhost.com:xxx.xxx.xxx.xxx"

每次我重新启动容器时,nginx 容器的 IP 地址都会发生变化,因此我需要以某种方式分配一个静态 IP 地址,这样我就不必不断地对 extra_hosts 部分进行硬编码。

Laradock 已经定义了 2 个网络接口:

networks:
  frontend:
    driver: bridge
  backend:
    driver: bridge

【问题讨论】:

  • @StockOverflaw, close but no ,它不是一个骗子。您的链接适用于版本 2,没有 laradock 及其额外的网络定义

标签: docker-compose laradock


【解决方案1】:

最后:而不是为 NGINX 容器分配静态 IP 并将域添加到 extra_hosts: 部分到 PHP_FPM 容器。 我在 NGINX 容器的网络部分添加了别名,像这样

### NGINX Server #########################################
    nginx:
      build:
        context: ./nginx
        args:
          - PHP_UPSTREAM_CONTAINER=${NGINX_PHP_UPSTREAM_CONTAINER}
          - PHP_UPSTREAM_PORT=${NGINX_PHP_UPSTREAM_PORT}
          - CHANGE_SOURCE=${CHANGE_SOURCE}
      volumes:
        - ${APP_CODE_PATH_HOST}:${APP_CODE_PATH_CONTAINER}${APP_CODE_CONTAINER_FLAG}
        - ${NGINX_HOST_LOG_PATH}:/var/log/nginx
        - ${NGINX_SITES_PATH}:/etc/nginx/sites-available
        - ${NGINX_SSL_PATH}:/etc/nginx/ssl
      ports:
        - "${NGINX_HOST_HTTP_PORT}:80"
        - "${NGINX_HOST_HTTPS_PORT}:443"
      depends_on:
        - php-fpm 
        - memcached       
      networks:
        frontend:              
        backend:
         aliases:
          - api.localhost.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-03-12
    • 1970-01-01
    • 2017-01-22
    • 2022-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    相关资源
    最近更新 更多