我正在使用selenium服务器.它适用于测试在端口80上运行的应用程序.
但是,如果我测试在80以外的其他端口上运行的应用程序,例如5001,则拒绝连接.
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities;
br = webdriver.Remote(command_executor="http://localhost:4444/wd/hub", desired_capabilities=DesiredCapabilities.CHROME)
br.get("http://127.0.0.1:5001/login/")
br.get_screenshot_as_file("/tmp/test.png")
Run Code Online (Sandbox Code Playgroud)
如何在端口5001上进行测试?
编辑
我使用docker-compose运行Selenium服务器作为Docker容器:
version: '2'
services:
selenium:
image: selenium/standalone-chrome:latest
ports:
- 4444:4444
Run Code Online (Sandbox Code Playgroud) 我的主机上有一个 API 在端口 8000 上运行。同时,我有一个 docker compose 集群,其中有一个容器应该连接所述 API。为了获取请求的 url,我在 Windows 计算机上使用“host.docker.internal:8000”,效果非常好。但是,我有一个 Linux 部署服务器,其中“host.docker.internal”无法解析任何内容,导致 API 连接错误。我在stackoverflow 上的另一篇文章中看到,您通过在 Linux 上添加以下内容来解决此问题docker-compose.yaml
services:
service_name:
extra_hosts:
- host.docker.internal:host-gateway
Run Code Online (Sandbox Code Playgroud)
这将 docker0 IP 添加到/etc/hosts
,但是当我尝试执行 GET 请求时,生成的消息是:
Failed to connect to host.docker.internal port 8000: Connection refused
我现在真的很困惑。我不知道这是否是防火墙问题、docker问题、docker compose问题、docker on linux问题。请帮忙...
随着 Docker 的出现20.10
,host-gateway
应该可以在 Linux 平台上使用(详见这个精彩的答案)。因此,应该可以创建一个docker-compose
与平台无关的脚本。(我本人使用的是 Debian。)
以下是一些问题和答案的链接,对我到目前为止有帮助:这里,这里,和这里(以及一些其他答案和评论)
我正在尝试创建一个用于运行The Graph 的脚本,其中涉及在 Docker 容器内运行ipfs
并postgres
连接到 Docker 外部的区块链实例(在端口 8545 上)。这是脚本:
version: '3'
services:
graph-node:
extra_hosts:
- "host.docker.internal:host-gateway"
image: graphprotocol/graph-node
ports:
- '8000:8000'
- '8001:8001'
- '8020:8020'
- '8030:8030'
- '8040:8040'
depends_on:
- ipfs
- postgres
environment:
postgres_host: postgres
postgres_user: graph-node
postgres_pass: let-me-in
postgres_db: graph-node
ipfs: 'ipfs:5001'
ethereum: 'localhost:http://host.docker.internal:8545'
RUST_LOG: info
ipfs:
image: ipfs/go-ipfs:v0.4.23
ports: …
Run Code Online (Sandbox Code Playgroud) 我的应用程序在docker镜像中运行(我的开发团队从不在他们的机器中安装软件,只有docker镜像具有依赖关系).
我需要使用pycharm调试器调试一些东西,如何将pycharm的调试器连接到docker image的python?
根据此处的 docker 文档
https://docs.docker.com/network/host/
主机网络驱动程序仅适用于 Linux 主机,在 Docker for Mac、Docker for Windows 或 Docker EE for Windows Server 上不受支持。
在 Mac 上,人们使用哪些替代方案?
我的场景
最简单/最优雅的解决方案是什么?
这是我的 docker-compose.yml 我试图在我的本地项目上运行 cypress,但它拒绝在端口上运行。我做错了什么?
version: '3.2'
# run Cypress tests and exit with command
# docker-compose up --exit-code-from cypress
services:
cypress:
# the Docker image to use from https://github.com/cypress-io/cypress-docker-images
image: "cypress/included:5.0.0"
environment:
- CYPRESS_baseUrl=http://localhost:3000
# share the current folder as volume to avoid copying
working_dir: /e2e
command: "--browser chrome"
ports:
- 3333:3000
volumes:
- ./:/e2e
Run Code Online (Sandbox Code Playgroud)
compose-docker 的结果:
cypress_1 |
cypress_1 | Cypress automatically waits until your server is accessible before running tests.
cypress_1 |
cypress_1 | We will try connecting …
Run Code Online (Sandbox Code Playgroud) Docker 容器(基于microsoft/dotnet-framework
映像)中的 .NET 应用程序无法连接到安装在 Docker 主机系统上的 SQL Server 2016。Docker 主机为 Windows Server 2016。Docker 版本为 17.03.2-ee-5。
我使用以下命令序列运行容器和 .NET 应用程序:
docker run -it microsoft/dotnet-framework cmd
docker cp App <container-id>:/
docker exec -it <container-id> cmd
cd App
TestConn.exe
Run Code Online (Sandbox Code Playgroud)
TestConn.exe 在大约 10 秒后抛出异常,抱怨它无法连接到 SQL Server。连接字符串是:
Data Source=localhost;Initial Catalog=SomeDB;Persist Security Info=False;User ID=appuser;Password=apppwd;MultipleActiveResultSets=False;Connection Timeout=30;
Run Code Online (Sandbox Code Playgroud)
如果我在 Docker 主机系统中运行 TestConn.exe,则应用程序成功连接到 SQL Server。
我添加--expose=1433
到docker run
命令 - 没有用。我希望它起作用的方式是 TestConn.exe 尝试连接到 localhost(默认 SQL 端口 1433),然后连接到 Docker 主机中的端口 1433,该端口对应于 SQL Server。
我的计算机上有一个应用程序在 localhost:1235 上运行,我正在尝试对其进行负载测试。
我为docker安装了k6容器来测试它,但当然从docker的性质来看,我的容器有不同的localhost。我试图理解要做什么。
我运行以下命令:
docker run -it --rm --net=host -v c:/users/k6:/k6 loadimpact/k6 run /k6/script
我在某处读到 --net=host 在 Windows 上不起作用,对吗?如何找到主机IP?
我尝试按照本教程运行: http://blog.michaelhamrah.com/2014/06/accessing-the-docker-host-server-within-a-container/
我找到的IP 172.17.0.1 在我的测试中不起作用。
我也尝试添加-p 1235:1235
但失败了,我猜docker尝试绑定这个端口并转发到它。
预先致谢,柴姆
aws ssm start-session --target <instance-id> --document-name AWS-StartPortForwardingSessionToRemoteHost --parameters host="mydb.example.us-east-2.rds.amazonaws.com",portNumber="3306",localPortNumber="3306"
Run Code Online (Sandbox Code Playgroud)
http://127.0.0.1:3306/
这样的 GUI在本地连接到它。无需使用 SSH。http://127.0.0.1:3306/
,则会收到错误Connection refused
。127.0.0.1
解析为 docker 容器的本地主机而不是我机器的本地主机。host.docker.internal ... resolves to the internal IP address used by the host
http://host.docker.internal:3306/ …
amazon-web-services amazon-rds docker aws-lambda aws-sam-cli
docker ×8
linux ×2
localhost ×2
amazon-rds ×1
aws-lambda ×1
aws-sam-cli ×1
cypress ×1
debugging ×1
deployment ×1
django ×1
fig ×1
host ×1
k6 ×1
macos ×1
podman ×1
pycharm ×1
selenium ×1
windows ×1