Repository navigation
Closed
Description
Describe the bug
I'm trying to use a Postgres container, but when I try and create it via a context manager, it never actually succeeds. If I run from terminal with debug logs I see the following over and over:
INFO testcontainers.core.waiting_utils:waiting_utils.py:46 Waiting to be ready...
In Docker, the container is running and here are the logs:
2023-02-07 20:38:51 The files belonging to this database system will be owned by user "postgres".
2023-02-07 20:38:51 This user must also own the server process.
2023-02-07 20:38:51
2023-02-07 20:38:51 The database cluster will be initialized with locale en_US.utf8.
2023-02-07 20:38:51 The default database encoding has accordingly been set to UTF8.
2023-02-07 20:38:51 The default text search configuration will be set to "english".
2023-02-07 20:38:51
2023-02-07 20:38:51 fixing permissions on existing directory /var/lib/postgresql/data ... ok
2023-02-07 20:38:51 creating subdirectories ... ok
2023-02-07 20:38:51 selecting default max_connections ... 100
2023-02-07 20:38:51 selecting default shared_buffers ... 32MB
2023-02-07 20:38:51 creating configuration files ... ok
2023-02-07 20:38:52 creating template1 database in /var/lib/postgresql/data/base/1 ... ok
2023-02-07 20:38:52 initializing pg_authid ... ok
2023-02-07 20:38:52 initializing dependencies ... ok
2023-02-07 20:38:52 creating system views ... ok
2023-02-07 20:38:52 loading system objects' descriptions ... ok
2023-02-07 20:38:52 creating conversions ... ok
2023-02-07 20:38:52 creating dictionaries ... ok
2023-02-07 20:38:52 setting privileges on built-in objects ... ok
2023-02-07 20:38:52 creating information schema ... ok
2023-02-07 20:38:52 loading PL/pgSQL server-side language ... ok
2023-02-07 20:38:52 vacuuming database template1 ... ok
2023-02-07 20:38:52 copying template1 to template0 ... ok
2023-02-07 20:38:52 copying template1 to postgres ... ok
2023-02-07 20:38:52
2023-02-07 20:38:52 Success. You can now start the database server using:
2023-02-07 20:38:52
2023-02-07 20:38:52 postgres -D /var/lib/postgresql/data
2023-02-07 20:38:52 or
2023-02-07 20:38:52 pg_ctl -D /var/lib/postgresql/data -l logfile start
2023-02-07 20:38:52
2023-02-07 20:38:52 waiting for server to start....LOG: database system was shut down at 2023-02-07 20:38:52 UTC
2023-02-07 20:38:52 LOG: autovacuum launcher started
2023-02-07 20:38:52 LOG: database system is ready to accept connections
2023-02-07 20:38:53 done
2023-02-07 20:38:53 server started
2023-02-07 20:38:53 CREATE DATABASE
2023-02-07 20:38:53
2023-02-07 20:38:53 CREATE ROLE
2023-02-07 20:38:53
2023-02-07 20:38:53
2023-02-07 20:38:53 /docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2023-02-07 20:38:53
2023-02-07 20:38:53 LOG: received fast shutdown request
2023-02-07 20:38:53 waiting for server to shut down...LOG: aborting any active transactions
2023-02-07 20:38:53 .LOG: autovacuum launcher shutting down
2023-02-07 20:38:53 LOG: shutting down
2023-02-07 20:38:53 LOG: database system is shut down
2023-02-07 20:38:54 done
2023-02-07 20:38:54 server stopped
2023-02-07 20:38:54
2023-02-07 20:38:54 PostgreSQL init process complete; ready for start up.
2023-02-07 20:38:54
2023-02-07 20:38:52
2023-02-07 20:38:52 WARNING: enabling "trust" authentication for local connections
2023-02-07 20:38:52 You can change this by editing pg_hba.conf or using the -A option the
2023-02-07 20:38:52 next time you run initdb.
2023-02-07 20:38:54 LOG: database system was shut down at 2023-02-07 20:38:53 UTC
2023-02-07 20:38:54 LOG: autovacuum launcher started
2023-02-07 20:38:54 LOG: database system is ready to accept connections
To Reproduce
Running on Windows with Docker desktop set to Linux containers:
with PostgresContainer("postgres:15.1") as container:
print("Connected")Note: I've tried various different docker images as far back as 9.0.22. All have exactly the same issue.
Runtime environment
Windows: 11 Version 22H2 (22621.1105)
Python: 3.10.9
Docker:
Client:
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc., v0.10.0)
compose: Docker Compose (Docker Inc., v2.15.1)
dev: Docker Dev Environments (Docker Inc., v0.0.5)
extension: Manages Docker extensions (Docker Inc., v0.2.17)
sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
scan: Docker Scan (Docker Inc., v0.23.0)
Server:
Containers: 1
Running: 1
Paused: 0
Stopped: 0
Images: 11
Server Version: 20.10.22
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
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: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9ba4b250366a5ddde94bb7c9d1def331423aa323
runc version: v1.1.4-0-g5fd4c4d
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 5.10.102.1-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 15.59GiB
Name: docker-desktop
ID: K6VR:4LG2:KIXZ:7XV7:SAPD:B6Z7:F22L:S3F3:MPBJ:YHV2:LNFX:MT2U
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5000
127.0.0.0/8
Live Restore Enabled: false
Python packages:
pip freeze
anyio==3.6.2
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
astroid==2.14.1
attrs==22.2.0
azure-core==1.26.3
azure-identity==1.12.0
bandit==1.7.4
base58==2.1.1
black==23.1.0
cachetools==5.3.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.0.1
click==8.1.3
colorama==0.4.6
cryptography==39.0.0
deprecation==2.1.0
-e git+ssh://git@github.com/DevFusion-io/RestAPI.git@3a907df32de285557fff55af486775a8b9423cd6#egg=devfusionrestapi
dill==0.3.6
docker==6.0.1
exceptiongroup==1.1.0
fastapi==0.88.0
gitdb==4.0.10
GitPython==3.1.30
google-api-core==2.11.0
google-auth==2.16.0
googleapis-common-protos==1.58.0
greenlet==2.0.2
h11==0.14.0
httpcore==0.16.3
httpx==0.23.3
idna==3.4
iniconfig==2.0.0
install==1.3.5
isort==5.12.0
lazy-object-proxy==1.9.0
mailchimp-transactional==1.0.50
mccabe==0.7.0
msal==1.21.0
msal-extensions==1.0.0
mypy==0.991
mypy-extensions==1.0.0
opencensus==0.11.1
opencensus-context==0.1.3
opencensus-ext-azure==1.1.8
opencensus-ext-logging==0.1.1
packaging==23.0
pathspec==0.11.0
pbr==5.11.1
platformdirs==3.0.0
pluggy==1.0.0
portalocker==2.7.0
protobuf==4.21.12
psutil==5.9.4
psycopg2==2.9.5
psycopg2-binary==2.9.5
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pydantic==1.10.4
PyJWT==2.6.0
pylint==2.16.1
pytest==7.2.1
python-dateutil==2.8.2
python-dotenv==0.21.1
pywin32==305
PyYAML==6.0
requests==2.28.2
result==0.9.0
rfc3986==1.5.0
rsa==4.9
sib-api-v3-sdk==7.5.0
six==1.16.0
smmap==5.0.0
sniffio==1.3.0
SQLAlchemy==2.0.2
starlette==0.22.0
stevedore==4.1.1
testcontainers==3.7.1
testcontainers-core==0.0.1rc1
testcontainers-postgres==0.0.1rc1
tomli==2.0.1
tomlkit==0.11.6
types-requests==2.28.11.12
types-urllib3==1.26.25.5
typing_extensions==4.4.0
urllib3==1.26.14
uvicorn==0.20.0
websocket-client==1.5.1
wrapt==1.14.1
Reacted by Hashan Jay`
Activity
JamesSommerville commentedon Feb 7, 2023
I am also encountering this same issue:
Postgres: 13.9
Windows: 10
Similar python packages and docker configuration relative to above
my co workers that are using Mac are having no issues running the same code.
tillahoffmann commentedon Feb 17, 2023
Do you have a copy of the final error message when the test eventually fails? This might be the same issue as #108, and @ikravets might have a fix in #283.
JamesSommerville commentedon Feb 17, 2023
the final error message that I receive is the following:
testcontainers.core.exceptions.TimeoutException: Wait time (120s) exceeded for _connect(args: (), kwargs {}). Exception: (psycopg2.OperationalError) could not translate host na me "localnpipe" to address: Unknown hostit does seem that the workarounds proposed in #108 are working as fixes
tillahoffmann commentedon Feb 17, 2023
Thanks for sharing, @JamesSommerville. This is indeed the same issue as #108. Development for Windows is both slow and unreliable as I don't have access to a Windows machine, and GitHub Actions does not yet support running linux containers on Windows runners (cf. #310). Let's continue the discussion in #108.