我正在嘗試使用Docker和Selenium Grid來設置自動化測試平臺。在下圖中,您可以看到我正在使用的結構。最上面是在Compute Engine上運行的Ubuntu服務器。左邊是運行ubuntu 14.04的docker容器。容器使用Google App Engine在localhost:8080上運行我們的項目。右邊是硒與集線器端口上運行兩個節點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中打開了這些端口。
在碼頭集裝箱中,我使用Google App Engine sdk在本地運行項目。使用docker exec -it drunk_kalam bash
後,我激活App Engine服務器。該命令從Docker容器內運行。將來這將成爲腳本的一部分,但由於這仍然是一項正在進行的工作,因此它將從容器中運行。下面你可以看到該項目運行:
[email protected]:/# 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集線器,並且此端口是可訪問的。當運行以下命令:
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
當我的搬運工容器上的nmap 8080運行運行的項目,我得到這樣的輸出:
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
我能夠訪問32777端口。但映射將不起作用,因爲8080端口已關閉。因此,我的Ubuntu主機無法訪問Docker容器。我試圖將它映射到非隨機端口上,但泊塢窗容器上的8080端口保持關閉的事實不會改變。 – Tijn
什麼應該在端口8080上監聽?從你的ps輸出中,你啓動了bash。外殼本身不會偵聽網絡流量。 – BMitch
在碼頭集裝箱中,我使用Google App Engine sdk在本地運行我們的網站。這在8080端口上是有效的。我不能在沒有監聽端口8080的情況下訪問它。澄清:Selenium集線器應該在Docker容器的本地主機上運行測試。 – Tijn