- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开发了一些 Python3 脚本来在 Standalone Selenium Chrome 之上运行与 TCP 服务器的图像来执行一些进程,该进程收集测试期间创建的一些信息,并且这些信息位于容器内。每当我需要启动 python3 进程时,我都会通过 TCP 客户端连接到它,发送一些命令,然后 python3 脚本就会执行我需要它执行的操作。
在我的 dockerfile 上,我安装了 pip3 和我需要的所有内容,然后复制了我需要的所有脚本,如果我手动访问 docker 容器,并且手动启动 python3 脚本,一切都会完美运行,如下所示:
docker exec -it selc bash
cd /home/seluser/python/
sudo nohup python3 myscript.py &
这成功地在后台启动了我的 python3 脚本,并且运行得很好
seluser@24d2713db5f1:~/python$ sudo nohup python3 myscript.py &
[1] 71
seluser@24d2713db5f1:~/python$ nohup: ignoring input and appending output to 'nohup.out'
但是,我希望每当启动容器时自动执行此脚本,但我无法成功执行此操作。当我运行容器时,我在容器日志中收到 ConnectionRefusedError: [Errno 111] Connection returned
错误。下面是我的 dockerfile
FROM selenium/standalone-chrome-debug
USER root
RUN apt-get update &&\
apt-get upgrade -y &&\
apt-get install python3-pip -y &&\
apt-get install dos2unix -y &&\
pip3 install pynput &&\
pip3 install azure.storage.blob &&\
apt-get install vim -y
USER seluser
EXPOSE 9871
RUN mkdir -p /home/seluser/upload &&\
mkdir -p /home/seluser/python &&\
mkdir -p /home/seluser/logs &&\
mkdir -p /home/seluser/debug
ADD /python /home/seluser/python
USER root
COPY entry_point.sh /opt/bin/entry_point.sh
RUN dos2unix /opt/bin/entry_point.sh &&\
chmod a+x /opt/bin/entry_point.sh
USER seluser
下面是我从 selenium github 获取的 shell 脚本entry_point.sh,只需修改即可运行我的脚本
#!/usr/bin/env bash
if ! whoami &> /dev/null; then
if [ -w /etc/passwd ]; then
echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
fi
fi
/usr/bin/supervisord --configuration /etc/supervisord.conf &
SUPERVISOR_PID=$!
function shutdown {
echo "Trapped SIGTERM/SIGINT/x so shutting down supervisord..."
kill -s SIGTERM ${SUPERVISOR_PID}
wait ${SUPERVISOR_PID}
echo "Shutdown complete"
}
echo "Starting script PYTHON3"
nohup python3 /home/seluser/python/myscript.py &
echo "script PYTHON3 started"
trap shutdown SIGTERM SIGINT
wait ${SUPERVISOR_PID}
这是我启动的 myscript.py
import asyncio
import logging
import time
from servico.myserver import myServer
from auxiliar.objlog import ObjLog
from auxiliar.objip import ObjIp
logger = ObjLog().executar()
logger.debug("Starting execution")
time.sleep(3)
logger.debug("Getting connection")
loop = asyncio.get_event_loop()
stream_server = myServer(loop)
# ip = ObjIp().executar()
# logger.debug('IP:' + ip)
coro_server = asyncio.start_server(
stream_server.server_handler,
'0.0.0.0',
9871,
loop=stream_server.loop
)
server = loop.run_until_complete(coro_server)
logger.debug('Pre-execution')
logger = ObjLog().executar()
logger.debug('Listening:' + str(server.sockets[0].getsockname()))
try:
loop.run_forever()
except KeyboardInterrupt:
pass
print('Closing Server')
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()
我使用此 docker run 命令启动容器
docker run --name selc --detach --rm -p 4444:4444 -p 5900:5900 -p 9871:9871 mydocker/selenium-debug-chrome:latest
启动容器时得到的日志如下
λ docker logs selc
Iniciando script PYTHON3
script PYTHON3 iniciado
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/Xlib/support/unix_connect.py", line 119, in get_socket
s = _get_unix_socket(address)
File "/usr/local/lib/python3.6/dist-packages/Xlib/support/unix_connect.py", line 98, in _get_unix_socket
s.connect(address)
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/Xlib/support/unix_connect.py", line 123, in get_socket
s = _get_tcp_socket(host, dno)
File "/usr/local/lib/python3.6/dist-packages/Xlib/support/unix_connect.py", line 93, in _get_tcp_socket
s.connect((host, 6000 + dno))
ConnectionRefusedError: [Errno 111] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/seluser/python/my.py", line 5, in <module>
from servico.myserver import myServer
File "/home/seluser/python/servico/myserver.py", line 7, in <module>
from servico.tarefas.download_pdf import DownloadPdf
File "/home/seluser/python/servico/tarefas/download_pdf.py", line 5, in <module>
from pynput.keyboard import Key, Controller
File "/usr/local/lib/python3.6/dist-packages/pynput/__init__.py", line 23, in <module>
from . import keyboard
File "/usr/local/lib/python3.6/dist-packages/pynput/keyboard/__init__.py", line 49, in <module>
from ._xorg import KeyCode, Key, Controller, Listener
File "/usr/local/lib/python3.6/dist-packages/pynput/keyboard/_xorg.py", line 39, in <module>
from pynput._util.xorg import (
File "/usr/local/lib/python3.6/dist-packages/pynput/_util/xorg.py", line 40, in <module>
_check()
File "/usr/local/lib/python3.6/dist-packages/pynput/_util/xorg.py", line 38, in _check
display = Xlib.display.Display()
File "/usr/local/lib/python3.6/dist-packages/Xlib/display.py", line 89, in __init__
self.display = _BaseDisplay(display)
File "/usr/local/lib/python3.6/dist-packages/Xlib/display.py", line 71, in __init__
protocol_display.Display.__init__(self, *args, **keys)
File "/usr/local/lib/python3.6/dist-packages/Xlib/protocol/display.py", line 89, in __init__
self.socket = connect.get_socket(name, protocol, host, displayno)
File "/usr/local/lib/python3.6/dist-packages/Xlib/support/connect.py", line 87, in get_socket
return mod.get_socket(dname, protocol, host, dno)
File "/usr/local/lib/python3.6/dist-packages/Xlib/support/unix_connect.py", line 127, in get_socket
raise error.DisplayConnectionError(dname, str(val))
Xlib.error.DisplayConnectionError: Can't connect to display ":99.0": [Errno 111] Connection refused
2019-03-16 14:00:59,881 INFO Included extra file "/etc/supervisor/conf.d/selenium-debug.conf" during parsing
2019-03-16 14:00:59,881 INFO Included extra file "/etc/supervisor/conf.d/selenium.conf" during parsing
2019-03-16 14:00:59,885 INFO supervisord started with pid 7
2019-03-16 14:01:00,887 INFO spawned: 'xvfb' with pid 13
2019-03-16 14:01:00,888 INFO spawned: 'fluxbox' with pid 14
2019-03-16 14:01:00,890 INFO spawned: 'vnc' with pid 15
2019-03-16 14:01:00,891 INFO spawned: 'selenium-standalone' with pid 16
2019-03-16 14:01:01,016 INFO success: xvfb entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)2019-03-16 14:01:01,016 INFO success: fluxbox entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
2019-03-16 14:01:01,016 INFO success: vnc entered RUNNING state, process has stayed up for > than 0 seconds (startsecs) 2019-03-16 14:01:01,017 INFO success: selenium-standalone entered RUNNING state, process has stayed up for > than 0 seconds (startsecs)
14:01:01.332 INFO [GridLauncherV3.parse] - Selenium server version: 3.141.59, revision: e82be7d358
14:01:01.429 INFO [GridLauncherV3.lambda$buildLaunchers$3] - Launching a standalone Selenium Server on port 4444
2019-03-16 14:01:01.489:INFO::main: Logging initialized @570ms to org.seleniumhq.jetty9.util.log.StdErrLog
14:01:01.822 INFO [WebDriverServlet.<init>] - Initialising WebDriverServlet
14:01:01.941 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
如果我通过 bash 手动连接到它,并按照我指出的方式启动它,它就可以正常工作。它只是在启动时不起作用。
为什么我会收到此错误?还有其他方法可以在容器启动后自动启动 python3 脚本吗?非常感谢您的帮助。
编辑
基于基础镜像,它已经有一个 shell 脚本的入口点。看看docker检查
我可以看到它。
λ docker inspect selc
[
{
"Id": "24d2713db5f13be0c69479a27f6ea4c943d194edbe3b2fa303aaac966639694e",
"Created": "2019-03-16T14:31:43.6236537Z",
"Path": "/opt/bin/entry_point.sh",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 34191,
"ExitCode": 0,
"Error": "",
"StartedAt": "2019-03-16T14:31:44.2388239Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
我不想改 rebase 础图像工作的机制,只是稍微调整一下以尝试使用现有代码执行我的脚本。但我对想法持开放态度,因为我不知道该怎么做。
最佳答案
由于您有 supervisord
,更好的方法是通过它运行 python 脚本,而不是使用 nohup
。因此,创建一个类似 myscript.conf
[program:myscript]
command=/usr/bin/python3 /home/seluser/python/myscript.py
autostart=true
autorestart=true
startretries=3
user=seluser
在你的 Dockerfile 中替换以下行:
COPY entry_point.sh /opt/bin/entry_point.sh
RUN dos2unix /opt/bin/entry_point.sh &&\
chmod a+x /opt/bin/entry_point.sh
下面这个:
According to the main configuration file of
docker-selenium
, any additional config should be add to/etc/supervisor/conf.d/
COPY myscript.conf /etc/supervisor/conf.d/
并且不需要修改入口点脚本,因为我们用supervisord配置文件替换了nohup
关于python - 尽管 shell 脚本抛出 [Errno 111] 连接被拒绝,但在 Docker 启动时使用 TCP 服务器执行 python3 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55198580/
我只想允许一个国家/地区访问,但排除该国家/地区内的代理。 这就是我所拥有的(为了方便起见,缩短了版本) order deny,allow deny from all allow from 139.
这个问题在这里已经有了答案: What is an unhandled promise rejection? (9 个回答) 关闭 4 年前。 我目前正在尝试实现我自己的 Promise,以便在 A
我在使用 Gitolite 推送 git 时遇到问题。 当我尝试这个时: git push origin :refs/tags/deployment 我收到这个错误: remote: D NAME/i
我已经为我的 laravel 5.0-dev 项目配置了 mysql,如下所示: 'mysql' => [ 'driver' => 'mysql', 'host' =>
我对 Web 和 SOF 进行了一些研究,但发现对于该错误没有任何真正的帮助。 我使用 Windows 10 Ubuntu Bash 安装了 Node 和 Puppeteer,但未能使其工作,但我设法
在我的应用审核期间,我收到了以下信息: “17.2:要求用户共享个人信息(例如电子邮件地址和生日)才能正常运行的应用将被拒绝 具体来说,您的应用仅使用Facebook登录名进行身份验证,但不包括该网站
我正在开发 VeriFone VX 终端的接口(interface)。虽然,这确实是一个普遍的 EMV 问题。我们的处理器的下限为零,因此它将始终在线发送。但是,如果它发生变化,您如何知道(哪些标签)
我编写了一些宏代码,根据表单提交向经理发送电子邮件(用于费用/审批流程),这是我使用谷歌表单/电子表格的第一个项目,所以也许我可能会错过一些简单的东西,但我为此浏览了 2 个教程,我的代码与重要的部分
clang 3.4 接受以下代码;而 vc++ NOV 2013 CTP 拒绝它并出现错误: error C2668: 'AreEqual' : ambiguous call to overloade
使用 nginx,您可以允许和拒绝范围和 ips (https://www.nginx.com/resources/admin-guide/restricting-access/)。使用realip模
官方编辑: 非常感谢您的帮助,但我仍然遇到问题。 我的 ffserver.conf 文件是这样的: # Port on which the server is listening. You must
我有一个问题:我是 Ubuntu 系统的根。我想授予用户(比如用户名是 X)执行任何命令的权限,但同时我有一个文件夹,除了我的用户(当然不是 X,因为它是 Admin ) 或根。有什么建议么?谢谢!
我使用 Apache2.2 作为 tomcat 服务器的前端。我想限制对某个位置的访问,但允许对子位置的所有访问,但遇到了一些麻烦。 我目前拥有的是: AllowOverride None
就像 this person ,我一直在为浏览器缓存 SSL session 而苦苦挣扎。简而言之,如果选择了客户端证书,则无法以编程方式清除状态,除非在 IE 中使用 document.execCo
我的网站是在由 Apache 服务器提供服务的 Angular 上设置的。我通过 View 将内容动态加载到主页上。 现在以下是我的问题: 我建立这个网站的主要目的是通过 google adsense
我最近遇到了我的应用程序的问题,当它突然被 Google Play 拒绝时因为他们发现我使用的是背景位置 .但实际上我并没有使用这个功能。我只有 ACCESS_COARSE_LOCATION和 ACC
function sendPushNotification(subscription, urlEncodedData){ try { webpush.sendNotification(su
我包裹了一个 request-promise-native调用返回 promise 的函数。 import request from 'request-promise-native'; functio
我正在开发我的 meteor 项目,并开始设置我的第一个更复杂的允许/拒绝规则。我发现很难看出哪些允许触发,哪些不允许触发,以及这些函数中的某些变量包含什么。例如: List.allow({ u
我正在 AngularJS 中创建一个 Factory,它是这样的: if (href) { return $http({ method: method, url: item.href });
我是一名优秀的程序员,十分优秀!