Docker 容器外的虚拟主机

Docker Virtualhost outside container

Docker 运行 正确,但我想更改服务器名称的名称,现在可以使用这种方式 http://localhost:8080,但我想使用另一个 url同一个主机,有可能吗?

我已经在容器内配置了虚拟主机,并在我容器内的所有内容中添加 127.0.0.1 test.local /etc/hosts
现在,从我的容器内部,URL(test.local) 响应良好,但是当我从外部尝试时,只对 localhost:8080 有效。

任何帮助

你的情况要问的主要问题是:

本地 Docker 使用虚拟主机开发

请阅读 --network=host 或 Docker-撰写 network_mode: "host"

请检查:

https://docs.docker.com/v17.09/engine/userguide/networking/default_network/configure-dns/

我认为您需要一个 docker 容器,它通过名称监听而不是使用具有不同端口的本地主机。

  1. 在 /etc/hosts

    中添加您需要的服务器名称的 dns 条目

    $纳米/etc/hosts

    127.0.0.1test.local

  2. 编辑 composer.yml

版本:'2'

 services: 
 web:
    build: ./docker/
    ports:
        - "80:80"
    volumes:
        - .:/var/www/app
    tty: true
    extra_hosts:
        - "test.local:127.0.0.1"
    hostname: test
    domainname: local
  1. 在 DockerFile 中添加服务器名称:

    运行 printf "127.0.0.1 api.local" >> /etc/hosts

  2. 在DockerFile中配置虚拟主机

  3. 构建容器:

    $ docker-合成-d

  4. 检查主机名是否已应用于容器:

$ docker exec -it test_local_web_1 主机名

应该return:

$test.local

  1. 检查服务器是 运行 并通过服务器名称侦听:

$ curl -get http://test.local