构建时可以将域绑定到 docker 容器吗?
It's possible to tie a domain to the docker container when building it?
目前我所在的公司有一个中央开发服务器,其中包含一个 LAMP 环境。每个开发人员都可以访问该应用程序:developer_username.domain.com
。我们正在处理的应用程序使用许可证,许可证是在每个域下生成的,并且只绑定到域,这意味着我不能使用其他开发人员的许可证。
下面的例子会给你一个思路:
developer_1.domain.com ==> license1
developer_2.domain.com ==> license2
developer_n.domain.com ==> licenseN
我正在尝试对这个环境进行 docker 化,至少在一个容器中包含 PHP 和 Apache,我能够创建我需要的一切并且它可以工作。看看这个 docker-compose.yml
:
version: '2'
services:
php-apache:
env_file:
- dev_variables.env
image: reypm/php55-dev
build:
context: .
args:
- PUID=1000
- PGID=1000
ports:
- "80:80"
- "9001:9001"
extra_hosts:
- "dockerhost:xxx.xxx.xxx.xxx"
volumes:
- ~/var/www:/var/www
这将构建我需要的东西,但是当我尝试访问服务器时出现问题,因为我正在使用 http://localhost
然后许可证将无法使用,我将无法使用该应用程序.
想法是作为 developer_username.domain.com
访问,所以我的问题是:这是一项应该在 Docker 文件或 Docker Compose 上完成的工作吗?我的意思是 image/container level 让我们说通过设置一个 ENV
var 或者这是主机上 /etc/hosts
的工作 运行 Docker?
主机名是在您启动容器时定义的,会覆盖您尝试放入映像中的任何内容。在高层次上,我建议混合使用自定义 docker-compose.yml 和每个开发人员的卷,但每个 运行 都是相同的图像。 docker-compose.yml 可以包括主机名和域设置。然后,文件系统上需要特定于主机名的所有其他内容,以及许可证本身,都应该指向卷上的文件。最后,包括一个入口点,如果新主机名以默认或空卷启动,它会做正确的事情,用新主机名数据填充它并提示许可证。
tl;dr
没有! Docker 不会为你做那个。
长答案:
你想要做的是在机器上有一个自定义主机名 hosting docker 映射到 Docker 中的容器组成网络。对吗?
让我们退后一步,看看 docker works 中的网络:
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
此网络不等于您的主机网络,如果没有明确的端口导出(针对特定容器),您将无法访问此网络。全部曝光 does, is that:
The exposed port is accessible on the host and the ports are available to any client that can reach the host.
从现在开始,您可以放置一个反向代理(如 nginx
),或者您可以编辑 /etc/hosts
来定义客户端如何访问主机(即 Docker 主机,机器运行 Docker 撰写).
目前我所在的公司有一个中央开发服务器,其中包含一个 LAMP 环境。每个开发人员都可以访问该应用程序:developer_username.domain.com
。我们正在处理的应用程序使用许可证,许可证是在每个域下生成的,并且只绑定到域,这意味着我不能使用其他开发人员的许可证。
下面的例子会给你一个思路:
developer_1.domain.com ==> license1
developer_2.domain.com ==> license2
developer_n.domain.com ==> licenseN
我正在尝试对这个环境进行 docker 化,至少在一个容器中包含 PHP 和 Apache,我能够创建我需要的一切并且它可以工作。看看这个 docker-compose.yml
:
version: '2'
services:
php-apache:
env_file:
- dev_variables.env
image: reypm/php55-dev
build:
context: .
args:
- PUID=1000
- PGID=1000
ports:
- "80:80"
- "9001:9001"
extra_hosts:
- "dockerhost:xxx.xxx.xxx.xxx"
volumes:
- ~/var/www:/var/www
这将构建我需要的东西,但是当我尝试访问服务器时出现问题,因为我正在使用 http://localhost
然后许可证将无法使用,我将无法使用该应用程序.
想法是作为 developer_username.domain.com
访问,所以我的问题是:这是一项应该在 Docker 文件或 Docker Compose 上完成的工作吗?我的意思是 image/container level 让我们说通过设置一个 ENV
var 或者这是主机上 /etc/hosts
的工作 运行 Docker?
主机名是在您启动容器时定义的,会覆盖您尝试放入映像中的任何内容。在高层次上,我建议混合使用自定义 docker-compose.yml 和每个开发人员的卷,但每个 运行 都是相同的图像。 docker-compose.yml 可以包括主机名和域设置。然后,文件系统上需要特定于主机名的所有其他内容,以及许可证本身,都应该指向卷上的文件。最后,包括一个入口点,如果新主机名以默认或空卷启动,它会做正确的事情,用新主机名数据填充它并提示许可证。
tl;dr
没有! Docker 不会为你做那个。
长答案:
你想要做的是在机器上有一个自定义主机名 hosting docker 映射到 Docker 中的容器组成网络。对吗?
让我们退后一步,看看 docker works 中的网络:
By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
此网络不等于您的主机网络,如果没有明确的端口导出(针对特定容器),您将无法访问此网络。全部曝光 does, is that:
The exposed port is accessible on the host and the ports are available to any client that can reach the host.
从现在开始,您可以放置一个反向代理(如 nginx
),或者您可以编辑 /etc/hosts
来定义客户端如何访问主机(即 Docker 主机,机器运行 Docker 撰写).