在我的本地主机上,我有一个Docker容器服务于一个PHP网站,我可以在我的浏览器中看到http://localhost/learnintouch/www/learnintouch.com/
,但如果可能,我希望以dev.learnintouch.com/
方式访问它。
我尝试使用docker run -d --name learnintouch -p 80:80 -p 443:443 --add-host "dev.learnintouch.com":127.0.0.1 -v /home/stephane/dev/php/learnintouch:/usr/bin/apache/htdocs/learnintouch stephaneeybert/learnintouch
运行我的容器,但这还不够。
容器Apache服务器使用以下虚拟主机:
<VirtualHost *:80>
ServerName dev.learnintouch.com
ServerAlias dev.learnintouch.com
DocumentRoot /usr/bin/apache/htdocs/learnintouch/www/learnintouch.com
CustomLog logs/learnintouch-access_log combined
<Directory "/usr/bin/apache/htdocs/learnintouch/www/learnintouch.com">
Include /usr/bin/apache/htdocs/learnintouch/engine/setup/url_rewrite.conf
</Directory>
AddDefaultCharset UTF-8
</VirtualHost>
我的主持人的/etc/hosts
包含:
127.0.0.1 localhost
127.0.1.1 stephane-ThinkPad-X301
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
我使用版本运行Docker:
$ docker version
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 05:33:38 2016
OS/Arch: linux/amd64
Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 05:33:38 2016
OS/Arch: linux/amd64
Docker信息:
$ docker info
Containers: 3
Running: 1
Paused: 0
Stopped: 2
Images: 150
Server Version: 1.12.1
Storage Driver: aufs
Root Dir: /home/stephane/programs/install/docker/aufs
Backing Filesystem: extfs
Dirs: 118
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: overlay bridge null host
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor seccomp
Kernel Version: 4.4.0-36-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 7.693 GiB
Name: stephane-ThinkPad-X301
ID: YMZD:RANJ:QIQ5:3KX3:GNQ6:UIGW:6NG3:YYPU:IABK:XVPI:KPUV:NPSC
Docker Root Dir: /home/stephane/programs/install/docker
Debug Mode (client): false
Debug Mode (server): false
Username: stephaneeybert
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
127.0.0.0/8
答案 0 :(得分:0)
The additional hosts you pass in with --add-host
option will modify your container's /etc/host, not the file on your host itself. For testing, you need to modify the /etc/host on the host running your browser. And for production, you'd need to update DNS to point to the docker host (or a load balancer that includes the docker host as its target).