Title: Bug: `ConnectionRefusedError: [Errno 111] Connection refused` via docker-compose on Github Actions · Issue #558 · testcontainers/testcontainers-python · GitHub
Open Graph Title: Bug: `ConnectionRefusedError: [Errno 111] Connection refused` via docker-compose on Github Actions · Issue #558 · testcontainers/testcontainers-python
X Title: Bug: `ConnectionRefusedError: [Errno 111] Connection refused` via docker-compose on Github Actions · Issue #558 · testcontainers/testcontainers-python
Description: Describe the bug This seems potentially related to #517 and #475 TLDR; I am able to connect to the PG testcontainer from within docker running locally on a macbook, but running in github actions I get a connection error. I'm experiencing...
Open Graph Description: Describe the bug This seems potentially related to #517 and #475 TLDR; I am able to connect to the PG testcontainer from within docker running locally on a macbook, but running in github actions I ...
X Description: Describe the bug This seems potentially related to #517 and #475 TLDR; I am able to connect to the PG testcontainer from within docker running locally on a macbook, but running in github actions I ...
Opengraph URL: https://github.com/testcontainers/testcontainers-python/issues/558
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: `ConnectionRefusedError: [Errno 111] Connection refused` via docker-compose on Github Actions","articleBody":"**Describe the bug**\r\n\r\nThis seems potentially related to https://github.com/testcontainers/testcontainers-python/issues/517 and https://github.com/testcontainers/testcontainers-python/issues/475\r\n\r\nTLDR; I am able to connect to the PG testcontainer from within docker running locally on a macbook, but running in github actions I get a connection error.\r\n\r\nI'm experiencing a `ConnectionRefusedError: [Errno 111] Connection refused` error when attempting connecting to the postgres testcontainer when running my tests via docker-compose on a Github action. However I am able to run the tests within docker-compose locally on my macbook.\r\n\r\nI followed the instructions here for running `testcontainers` from within docker\r\n\r\nhttps://golang.testcontainers.org/system_requirements/ci/gitlab_ci/#example-using-docker-socket\r\n\r\nThis is the error I see in Github Actions\r\n\r\n```python\r\n for _ in range(50):\r\n try:\r\n Reaper._socket = socket()\r\n\u003e Reaper._socket.connect((container_host, container_port))\r\nE ConnectionRefusedError: [Errno 111] Connection refused\r\n/venv/lib/python3.11/site-packages/testcontainers/core/container.py:228: ConnectionRefusedError\r\n```\r\n\r\nBelow is the full stack trace \r\n\r\n\u003cdetails\u003e\r\n\r\n\u003csummary\u003eGithub Actions Stack Trace\u003c/summary\u003e\r\n\r\n```\r\n________________________ ERROR at setup of test_search _________________________\r\n @pytest.fixture(scope=\"session\")\r\n def db_url():\r\n print(\"YO\")\r\n print(set([a[4][0] for a in socket.getaddrinfo(socket.gethostname(), None)]))\r\n\u003e with PostgresContainer(\"postgres:13.1\") as postgres:\r\ntests/conftest.py:21: \r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \r\n/venv/lib/python3.11/site-packages/testcontainers/core/container.py:111: in __enter__\r\n return self.start()\r\n/venv/lib/python3.11/site-packages/testcontainers/core/generic.py:70: in start\r\n super().start()\r\n/venv/lib/python3.11/site-packages/testcontainers/core/container.py:87: in start\r\n Reaper.get_instance()\r\n/venv/lib/python3.11/site-packages/testcontainers/core/container.py:188: in get_instance\r\n Reaper._instance = Reaper._create_instance()\r\n/venv/lib/python3.11/site-packages/testcontainers/core/container.py:242: in _create_instance\r\n raise last_connection_exception\r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ \r\ncls = \u003cclass 'testcontainers.core.container.Reaper'\u003e\r\n @classmethod\r\n def _create_instance(cls) -\u003e \"Reaper\":\r\n logger.debug(f\"Creating new Reaper for session: {SESSION_ID}\")\r\n \r\n Reaper._container = (\r\n DockerContainer(c.ryuk_image)\r\n .with_name(f\"testcontainers-ryuk-{SESSION_ID}\")\r\n .with_exposed_ports(8080)\r\n .with_volume_mapping(c.ryuk_docker_socket, \"/var/run/docker.sock\", \"rw\")\r\n .with_kwargs(privileged=c.ryuk_privileged, auto_remove=True)\r\n .with_env(\"RYUK_RECONNECTION_TIMEOUT\", c.ryuk_reconnection_timeout)\r\n .start()\r\n )\r\n wait_for_logs(Reaper._container, r\".* Started!\")\r\n \r\n container_host = Reaper._container.get_container_host_ip()\r\n container_port = int(Reaper._container.get_exposed_port(8080))\r\n \r\n last_connection_exception: Optional[Exception] = None\r\n for _ in range(50):\r\n try:\r\n Reaper._socket = socket()\r\n\u003e Reaper._socket.connect((container_host, container_port))\r\nE ConnectionRefusedError: [Errno 111] Connection refused\r\n/venv/lib/python3.11/site-packages/testcontainers/core/container.py:228: ConnectionRefusedError\r\n```\r\n\r\n\u003c/details\u003e\r\n\r\nThe following is my test setup:\r\n\r\n`conftest.py`\r\n```python\r\n@pytest.fixture(scope=\"session\")\r\ndef db_url():\r\n with PostgresContainer(\"postgres:13.1\") as postgres:\r\n url = postgres.get_connection_url()\r\n yield url\r\n```\r\n\r\nThe following is the docker command I'm using to run the tests via `make test`. I've also tried multiple variations of the volume mapping to with no luck. \r\n\r\n```make\r\ntest:\r\n\tdocker-compose run --rm \\\r\n\t -v ${PWD}:${PWD} -w ${PWD}/server \\\r\n\t -v /var/run/docker.sock:/var/run/docker.sock \\\r\n\t --entrypoint \"\" server poetry run pytest -vv\r\n```\r\n\r\nwhere the `server` image is in my `docker-compose.yml` is \r\n\r\n```yml\r\n server:\r\n container_name: svs_server\r\n platform: linux/amd64\r\n build: ./server\r\n image: \"svs_server:local\"\r\n ports:\r\n - \"8000:8000\"\r\n volumes:\r\n - \"./server:/app\"\r\n - \"./db:/app/db\"\r\n - \"./tmp:/tmp\"\r\n env_file:\r\n - .env\r\n - .env.secret\r\n ```\r\n\r\n\r\nI am able to successfully get the testcontainers/docker-compose setup running locally on my macbook (docker desktop) with the following, notice the only difference is the additional host override and lack of mapped volumes.\r\n\r\n```make\r\ntest-local:\r\n\tdocker-compose run --rm \\\r\n\t -v /var/run/docker.sock:/var/run/docker.sock \\\r\n\t -e TESTCONTAINERS_HOST_OVERRIDE=host.docker.internal \\\r\n\t --entrypoint \"\" server poetry run pytest -vv\r\n```\r\n\r\n\r\n**Runtime environment**\r\n\r\nI also tried finding more info about the network via running the following within the action.\r\n\r\n`print(set([a[4][0] for a in socket.getaddrinfo(socket.gethostname(), None)]))`\r\n\r\nThis returns an IP such as `{'172.18.0.2'}` but it is slightly different each time.\r\n\r\n- Running within Github Actions\r\n- Python 3.11 via the `FROM python:3.11-slim-buster` image\r\n- docker info\r\n```\r\nClient: Docker Engine - Community Version: 24.0.9 Context: default Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc.) Version: v0.14.0 Path: /usr/libexec/docker/cli-plugins/docker-buildx compose: Docker Compose (Docker Inc.) Version: v2.23.3 Path: /usr/libexec/docker/cli-plugins/docker-compose Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 14 Server Version: 24.0.9 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Using metacopy: false Native Overlay Diff: false userxattr: false Logging Driver: json-file Cgroup Driver: cgroupfs Cgroup Version: 2 Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc io.containerd.runc.v2 Default Runtime: runc Init Binary: docker-init containerd version: e377cd56a71523140ca6ae87e30244719194a521 runc version: v1.1.12-0-g51d5e94 init version: de40ad0 Security Options: apparmor seccomp Profile: builtin cgroupns Kernel Version: 6.5.0-1018-azure Operating System: Ubuntu 22.04.4 LTS OSType: linux Architecture: x86_64 CPUs: 2 Total Memory: 7.744GiB Name: fv-az822-516 ID: 584d62f5-11d9-4074-87e4-acacf60905a6 Docker Root Dir: /var/lib/docker Debug Mode: false Username: githubactions Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false\r\n```\r\n- docker-compose version\r\n`docker-compose version 1.29.2, build 5becea4c`\r\n\r\n- `uname -a`\r\n`Linux fv-az822-516 6.5.0-1018-azure #19~22.04.2-Ubuntu SMP Thu Mar 21 16:45:46 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux`\r\n\r\n---\r\n\r\nLet me know if there's any other additional debugging info I can provide that would help, thanks!!","author":{"url":"https://github.com/stv8","@type":"Person","name":"stv8"},"datePublished":"2024-04-28T17:54:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/558/testcontainers-python/issues/558"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:05f721ce-5016-76f5-65dd-fafa4184508c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C244:39FF2E:27DFEF:366A48:6A55392B |
| html-safe-nonce | d32fb41fc224cf7dae97157b388e4c8ee93f9b925c3402c13c21137f193276a3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjQ0OjM5RkYyRToyN0RGRUY6MzY2QTQ4OjZBNTUzOTJCIiwidmlzaXRvcl9pZCI6IjkzNDgxMzk5MTgzNDA0MDYxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fc46fa5221eeec84e0578e3925d4e4946907f7ccede448be4ac9ddcd80fd3fe4 |
| hovercard-subject-tag | issue:2267711565 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/testcontainers/testcontainers-python/558/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4c2b065628004ca289f528c60356b10c39d9e72f6a04d2b157417c5a0a8d53a1/testcontainers/testcontainers-python/issues/558 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c2b065628004ca289f528c60356b10c39d9e72f6a04d2b157417c5a0a8d53a1/testcontainers/testcontainers-python/issues/558 |
| og:image:alt | Describe the bug This seems potentially related to #517 and #475 TLDR; I am able to connect to the PG testcontainer from within docker running locally on a macbook, but running in github actions I ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | stv8 |
| hostname | github.com |
| expected-hostname | github.com |
| None | fbd8fce4d63ac394c5405faa20aa50d5c9e56b979ac43ee1b26f8e7c47c4cd89 |
| turbo-cache-control | no-preview |
| go-import | github.com/testcontainers/testcontainers-python git https://github.com/testcontainers/testcontainers-python.git |
| octolytics-dimension-user_id | 13393021 |
| octolytics-dimension-user_login | testcontainers |
| octolytics-dimension-repository_id | 85802819 |
| octolytics-dimension-repository_nwo | testcontainers/testcontainers-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 85802819 |
| octolytics-dimension-repository_network_root_nwo | testcontainers/testcontainers-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 811f50b757204c6a1b4da0ea780075b3e1cc9e57 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width