admin管理员组文章数量:1287581
I am trying to run Playwright tests within a GitLab CI/CD pipeline against a web service running in a Docker container. My gitlab-ci.yml
looks like this:
stages:
- test
services:
- docker:27-dind
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
container-tests:
stage: test
when: always
image: docker:27
script:
- docker run -d --name app -p 8000:80 image-name
- curl http://docker:8000 # This works!
- >
docker run --name tests -v "$(pwd)/tests:/tests"
mcr.microsoft/playwright/python:v1.50.0-noble /bin/sh -c "
pip install pytest-base-url pytest-playwright playwright &&
playwright install &&
pytest /tests --base-url='http://docker:8000'"
# This doesn't work!
The web service (app
container) starts and is accessible via curl http://docker:8000
. However, when I try to run Playwright tests from another container, it fails to reach the service using http://docker:8000
.
except Exception as error:
> raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
E playwright._impl._errors.Error: Page.goto: net::ERR_NAME_NOT_RESOLVED at http://docker:8000/
E Call log:
E - navigating to "http://docker:8000/", waiting until "load"
Is this the correct approach, or am I doing something fundamentally wrong? How can I properly configure the Playwright container so that it can connect to the web service container within the GitLab CI/CD pipeline?
Any guidance or best practices would be greatly appreciated!
I am trying to run Playwright tests within a GitLab CI/CD pipeline against a web service running in a Docker container. My gitlab-ci.yml
looks like this:
stages:
- test
services:
- docker:27-dind
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
container-tests:
stage: test
when: always
image: docker:27
script:
- docker run -d --name app -p 8000:80 image-name
- curl http://docker:8000 # This works!
- >
docker run --name tests -v "$(pwd)/tests:/tests"
mcr.microsoft/playwright/python:v1.50.0-noble /bin/sh -c "
pip install pytest-base-url pytest-playwright playwright &&
playwright install &&
pytest /tests --base-url='http://docker:8000'"
# This doesn't work!
The web service (app
container) starts and is accessible via curl http://docker:8000
. However, when I try to run Playwright tests from another container, it fails to reach the service using http://docker:8000
.
except Exception as error:
> raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
E playwright._impl._errors.Error: Page.goto: net::ERR_NAME_NOT_RESOLVED at http://docker:8000/
E Call log:
E - navigating to "http://docker:8000/", waiting until "load"
Is this the correct approach, or am I doing something fundamentally wrong? How can I properly configure the Playwright container so that it can connect to the web service container within the GitLab CI/CD pipeline?
Any guidance or best practices would be greatly appreciated!
Share Improve this question edited Feb 23 at 16:06 Jasper asked Feb 23 at 14:59 JasperJasper 1611 silver badge8 bronze badges2 Answers
Reset to default 1In the meantime, I found a solution to my question. I needed to add my app
container to the services with an alias to establish a connection. While executing commands inside this container is not possible, the app
container is successfully serving content and is accessible by the Playwright container.
container-tests:
stage: test
when: always
image: mcr.microsoft/playwright/python:v1.50.0-noble
services:
- name: ${CI_REGISTRY_IMAGE}
alias: app
script:
- pip install pytest-base-url pytest-playwright playwright
- playwright install
- pytest tests --base-url='http://app'
When you run a docker:dind service like this, the docker service becomes the host for any containers the pipeline runs. So, the pipeline can talk to any published ports using docker:{port}.
However, for containers launched on the docker:dind service, the normal connectivity rules apply: they should be able to connect to each other either using docker networking, or host.docker.internal.
本文标签: dockerPlaywright container cannot reach web service container in GitLab CICDStack Overflow
版权声明:本文标题:docker - Playwright container cannot reach web service container in GitLab CICD - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741314392a2371830.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论