我正在尝试使用Docker和Selenium Grid设置自动化测试平台.在下图中,您可以看到我正在使用的结构.最重要的是在Compute Engine上运行的ubuntu服务器.左边是一个运行ubuntu 14.04的docker容器.容器使用Google App Engine在localhost:8080上运行我们的项目.右侧是Selenium Hub,在端口4444上运行两个节点.
这是运行docker ps时的输出:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5ac6e3c8270 xxxxx/ubuntuport:14.04 "/bin/bash" 3 days ago Up 13 seconds 0.0.0.0:32777->8080/tcp drunk_kalam
4246ca0790db eu.gcr.io/xxxxxx/selenium-chrome "/bin/sh -c 'rm -rf /" 4 weeks ago Up 3 days evil_mahavira
8d06f90a1a84 eu.gcr.io/xxxxxx/selenium-firefox "/bin/sh -c 'rm -rf /" 4 weeks ago Up 3 days nauSEOus_torvalds
dc548f638778 eu.gcr.io/xxxxxx/selenium-hub "/opt/bin/entry_point" 4 weeks ago Up 3 days 0.0.0.0:32770->4444/tcp modest_khorana
正如您所看到的那样,集线器和ubuntu容器都已激活端口,并从运行docker容器的ubuntu主机转发.我在Google Compute Engine中打开了这些端口.
在docker容器中,我正在使用Google App Engine sdk在本地运行我们的项目.使用docker exec -it drunk_kalam bash之后我激活了App Engine服务器.该命令从docker容器中运行.将来,这将是脚本的一部分,但由于这仍然是一项正在进行的工作,因此它正在容器内运行.您可以在下面看到正在运行的项目:
root@f5ac6e3c8270:/# google_appengine/dev_appserver.py --PHP_executable_path=/usr/bin/PHP5-cgi --PHP_gae_extension_path=appengine-PHP-extension/modules/gae_runtime_module.so ./xxxxxxxxxxxxxxx/
INFO 2016-08-08 12:19:49,287 sdk_update_checker.py:229] Checking for updates to the SDK.
WARNING 2016-08-08 12:19:49,532 simple_search_stub.py:1146] Could not read search indexes from /tmp/appengine.xxxxxxxxxxx.root/search_indexes
INFO 2016-08-08 12:19:49,535 api_server.py:205] Starting API server at: http://localhost:39475
WARNING 2016-08-08 12:19:51,217 inotify_file_watcher.py:196] There are too many directories in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
INFO 2016-08-08 12:19:51,218 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO 2016-08-08 12:19:51,220 admin_server.py:116] Starting admin server at: http://localhost:8000
问题是我无法通过端口8080访问项目.我已经暴露了我的Dockerfile中的端口,并且我尝试使用-P标志以及-p 8080标志运行容器.像这样:
docker run -dPi xxxxx/ubuntuport:14.04
我已经使用完全相同的命令启动了selenium hub,并且可以访问此端口.运行以下命令时:
nmap -p 4444 172.17.0.3
我得到以下输出:
Nmap scan report for 172.17.0.3
Host is up (0.00010s latency).
PORT STATE SERVICE
4444/tcp open krb524
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds
当我在运行项目的docker容器上运行8080上的nmap时,我得到了这个输出:
Nmap scan report for 172.17.0.2
Host is up (0.000085s latency).
PORT STATE SERVICE
8080/tcp closed http-proxy
Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds
我相信问题出在ubuntu容器的Dockerfile中.下面你可以看到Dockerfile,它是来自官方ubuntu存储库的dockerfile,增加了EXPOSE 8080.
FROM scratch
ADD ubuntu-trusty-core-cloudimg-amd64-root.tar.gz /
EXPOSE 8080
# a few minor docker-specific tweaks
# see https://github.com/docker/docker/blob/9a9fc01af8fb5d98b8eec0740716226fadb3735c/contrib/mkimage/debootstrap
RUN set -xe \
\
&& echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
&& echo 'exit 101' >> /usr/sbin/policy-rc.d \
&& chmod +x /usr/sbin/policy-rc.d \
\
&& dpkg-divert --local --rename --add /sbin/initctl \
&& cp -a /usr/sbin/policy-rc.d /sbin/initctl \
&& sed -i 's/^exit.*/exit 0/' /sbin/initctl \
\
&& echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
\
&& echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
&& echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
&& echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
\
&& echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
\
&& echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes \
\
&& echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests
RUN rm -rf /var/lib/apt/lists/*
RUN sed -i 's/^#\s*\(deb.*universe\)$/\1/g' /etc/apt/sources.list
CMD ["/bin/bash"]
用于公开端口的命令与Selenium Hub的命令相同,只是使用不同的端口号.我似乎无法弄清楚为什么这个端口保持关闭状态.任何帮助,将不胜感激.
提前致谢
Tijn
如果要共享特定端口而不使用随机映射,可以使用小写p选项定义它:-p 8080:8080或甚至-p 8888:8080将端口8888映射到容器的端口8080.
从聊天会话中,结果是应用程序监听容器内的环回.使用netstat -lnt,它显示:
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN
更新应用程序以绑定到0.0.0.0允许端口转发按预期工作.