【发布时间】:2021-08-09 08:59:11
【问题描述】:
我有一个 vuejs 应用程序,我正在尝试设置使用 docker + docker-compose 的无头测试。我似乎无法解决服务似乎都可以正确启动但似乎无法相互通信的问题:
Dockerfile:
FROM node:lts-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install -f
EXPOSE 8080
# Note 8080 is exposed! I'm not crazy!
CMD ["npm", "run", "serve"]
docker-compose 文件:
version: '3.5'
services:
my-app:
build: .
ports:
- "8080:8080"
volumes:
- type: bind
source: ./app
target: /app
- "/app/node_modules"
cypress:
image: "cypress/included:8.2.0"
depends_on:
- my-app
#environment:
# - CYPRESS_baseUrl=http://localhost:8080
working_dir: /app
volumes:
- type: bind
source: ./app
target: /app
volumes:
app:
但是,cypress 会吐出如下错误:
cypress_1 | http://localhost:8080/thank-you
cypress_1 |
cypress_1 | We attempted to make an http request to this URL but the request failed without a response.
cypress_1 |
cypress_1 | We received this error at the network level:
cypress_1 |
cypress_1 | > Error: connect ECONNREFUSED 127.0.0.1:8080
cypress_1 |
cypress_1 | Common situations why this would fail:
cypress_1 | - you don't have internet access
cypress_1 | - you forgot to run / boot your web server
cypress_1 | - your web server isn't accessible
cypress_1 | - you have weird network configuration settings on your computer
cypress_1 | at http://localhost:44829/__cypress/runner/cypress_runner.js:143973:23
cypress_1 | at visitFailedByErr (http://localhost:44829/__cypress/runner/cypress_runner.js:143332:12)
cypress_1 | at http://localhost:44829/__cypress/runner/cypress_runner.js:143972:11
cypress_1 | at tryCatcher (http://localhost:44829/__cypress/runner/cypress_runner.js:13212:23)
cypress_1 | at Promise._settlePromiseFromHandler (http://localhost:44829/__cypress/runner/cypress_runner.js:11147:31)
cypress_1 | at Promise._settlePromise (http://localhost:44829/__cypress/runner/cypress_runner.js:11204:18)
cypress_1 | at Promise._settlePromise0 (http://localhost:44829/__cypress/runner/cypress_runner.js:11249:10)
cypress_1 | at Promise._settlePromises (http://localhost:44829/__cypress/runner/cypress_runner.js:11325:18)
cypress_1 | at _drainQueueStep (http://localhost:44829/__cypress/runner/cypress_runner.js:7919:12)
cypress_1 | at _drainQueue (http://localhost:44829/__cypress/runner/cypress_runner.js:7912:9)
cypress_1 | at Async.../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:44829/__cypress/runner/cypress_runner.js:7928:5)
cypress_1 | at Async.drainQueues (http://localhost:44829/__cypress/runner/cypress_runner.js:7798:14)
cypress_1 | From Your Spec Code:
cypress_1 | at Context.eval (http://localhost:44829/__cypress/tests?p=tests/e2e/specs/views/ThankYou.js:101:8)
cypress_1 |
cypress_1 | From Node.js Internals:
cypress_1 | Error: connect ECONNREFUSED 127.0.0.1:8080
cypress_1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
我曾经提出此设置的参考:
- https://www.cypress.io/blog/2019/05/02/run-cypress-with-a-single-docker-command/
- https://github.com/bahmutov/cypress-open-from-docker-compose/blob/master/e2e/docker-compose.yml
- https://github.com/bahmutov/demo-docker-cypress-included/blob/master/cy-run.sh
- https://github.com/cypress-io/cypress-example-docker-compose
注意:我尝试了许多 baseUrl 的变体(localhost、my-app 等)。所有这些都会导致相同的问题。
【问题讨论】:
-
也许 0.0.0.0:8080 会起作用?
-
CYPRESS_baseUrlenv 变量在 compose 文件中被注释掉,Cypress 是否需要它才能工作? -
@MarkoE 我已经尝试了很多变体,如我的帖子末尾所述。如果你有什么具体的,你认为我应该尝试,请指定。