且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Docker中使用/etc/hosts

更新时间:2021-07-28 06:59:04

您可以使用 jwilder/nginx -proxy ,它是由其他容器的环境变量自动配置的反向代理,因此您无需手动编写nginx代理配置.同样根据要求,它允许使用特定端口将请求转发到.

You can use a jwilder/nginx-proxy, it's a reverse proxy auto-configured by the env vars of other containers, so you don't need to manually write nginx proxy configs. Also as requested, it allows to use specific port to forward requests to.

# docker-compose.yml

version: '3.3'

services:

  lamp:
    environment:
      VIRTUAL_HOST: some_domain.dev
      VIRTUAL_PORT: 9999
    image: my_lamp_image

  app:
    environment:
      VIRTUAL_HOST: another_domain.dev
      VIRTUAL_PORT: 3000
    image: my_app_image

  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - 80:80
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

# /etc/hosts

127.0.0.1 some_domain.dev
127.0.0.1 another_domain.dev

jwilder/nginx-proxy具有许多更好的功能,例如ssl,uwsgi,fastcgi,也可以在生产中使用.还有伴侣"添加项,例如让我们加密ssl 中间代理服务器中的人.

jwilder/nginx-proxy has many more nice features like ssl, uwsgi, fastcgi and can also be used in production. There are also "companion" additions like let's encrypt ssl and man in the middle proxy.