Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP代码中使用curl重启docker,nginx的IP会变 #91

Closed
Fawkes-hub opened this issue Nov 29, 2018 · 4 comments
Closed

PHP代码中使用curl重启docker,nginx的IP会变 #91

Fawkes-hub opened this issue Nov 29, 2018 · 4 comments

Comments

@Fawkes-hub
Copy link

我下windows环境下配置了docker,安装DNMP成功,环境启动一切正常,但是需要一个功能使用curl功能,采用您说的方法后,可以设置成功,但是重启docker后,nginx的IP地址会改变,必须再重新设置,我这边应该如何配置可以使nginx的IP固定呢?

@Fawkes-hub Fawkes-hub changed the title HP代码中使用curl重启docker,nginx的IP会变 PHP代码中使用curl重启docker,nginx的IP会变 Nov 29, 2018
@yeszao
Copy link
Owner

yeszao commented Nov 29, 2018

可以配置静态IP。
在docker-compose.yml中。
首先,配置虚拟网卡driver和subnet:

networks:
  net-default:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 10.0.0.0/24

然后设置nginx的静态IP:

  nginx:
    #其他配置...
    networks:
      net-default:
        ipv4_address: 10.0.0.10

再在php中设置extra_hosts:

  php54:
    #其他配置...
    extra_hosts:
      - "project.com:10.0.0.10"
    networks:
      - net-default

最后重新build一下,就OK了。

@yeszao yeszao closed this as completed Dec 5, 2018
@549240290
Copy link

composesr 应该装到php容器中。。因为composer安装的时候会出现php版本问题
比如用composer安装laravel5.1 和 5.7。。就会报错

@popdaul
Copy link
Contributor

popdaul commented Dec 11, 2019

可以配置静态IP。
在docker-compose.yml中。
首先,配置虚拟网卡driver和subnet:

networks:
  net-default:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 10.0.0.0/24

然后设置nginx的静态IP:

  nginx:
    #其他配置...
    networks:
      net-default:
        ipv4_address: 10.0.0.10

再在php中设置extra_hosts:

  php54:
    #其他配置...
    extra_hosts:
      - "project.com:10.0.0.10"
    networks:
      - net-default

最后重新build一下,就OK了。

能否做一个容器的hosts映射在宿主机,我现在开发的微服务环境需要经常在本机和内网环境中切换,如果有一个单独的容器hosts文件映射在宿主机会方便修改

@Baiyinliang
Copy link

composesr 应该装到php容器中。。因为composer安装的时候会出现php版本问题

可以在后面增加 --ignore-platform-reqs即可,这样可以忽略版本问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants