testcontainers / testcontainers-python

Testcontainers is a Python library that providing a friendly API to run Docker container. It is designed to create runtime environment to use during your automatic tests.
https://testcontainers-python.readthedocs.io/en/latest/
Apache License 2.0
1.57k stars 283 forks source link

Bug: Can't find `docker` #723

Closed Chris-May-WS closed 3 hours ago

Chris-May-WS commented 4 hours ago

Describe the bug

I can't figure out how to get testcontainers to find my docker executable. I can't find a way to tell it where docker is or set up a test environment that helps testcontainers to know where docker is.

I even created a symlink to docker in the folder, but subprocess can't find it.

I can't find a way to customize testcontainers. what am I missing?

To Reproduce

from testcontainers.compose import DockerCompose

async def test__can_run():
    compose = DockerCompose(
        compose_folder, compose_file_name='docker-compose.yml', env_file=str(Path(__file__).parents[1] / 'testing.env')
    )
    with compose:
        assert True
>                   raise child_exception_type(errno_num, err_msg, err_filename)
E                   FileNotFoundError: [Errno 2] No such file or directory: 'docker'

../../../../.pyenv/versions/3.11.9/lib/python3.11/subprocess.py:1955: FileNotFoundError

Runtime environment

Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.

$ uname -a
Darwin WS-J26MXKQ4KP.tld 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6030 arm64

# Get the python version.
Python 3.11.9

# Get the docker version and other docker information.
docker client: 27.3.1
docker compose: 2.29.7
Installed packages

altair==5.4.1
annotated-types==0.7.0
anyio==4.4.0
attrs==24.2.0
blinker==1.8.2
cachetools==5.5.0
certifi==2024.8.30
cffi==1.17.1
cfgv==3.4.0
charset-normalizer==3.3.2
click==8.1.7
coverage==7.6.1
cryptography==43.0.1
distlib==0.3.8
dnspython==2.6.1
docker==7.1.0
docstring-parser==0.16
email-validator==2.2.0
environ-config==24.1.0
faker==28.4.1
fastapi==0.114.1
filelock==3.16.0
future==1.0.0
gax-google-logging-v2==0.8.3
gax-google-pubsub-v1==0.8.3
gcloud==0.18.3
gitdb==4.0.11
gitpython==3.1.43
google-api-core==2.19.2
google-auth==2.34.0
google-cloud-aiplatform==1.66.0
google-cloud-bigquery==3.25.0
google-cloud-core==2.4.1
google-cloud-firestore==2.18.0
google-cloud-resource-manager==1.12.5
google-cloud-storage==2.18.2
google-cloud-tasks==2.16.5
google-crc32c==1.6.0
google-gax==0.12.5
google-resumable-media==2.7.2
googleapis-common-protos==1.65.0
grpc-google-iam-v1==0.13.1
grpc-google-logging-v2==0.8.1
grpc-google-pubsub-v1==0.8.1
grpcio==1.66.1
grpcio-status==1.66.1
h11==0.14.0
httpcore==1.0.5
httplib2==0.22.0
httptools==0.6.1
httpx==0.27.2
identify==2.6.0
idna==3.8
iniconfig==2.0.0
itsdangerous==2.2.0
jinja2==3.1.4
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jwcrypto==1.5.6
markdown-it-py==3.0.0
markupsafe==2.1.5
mdurl==0.1.2
narwhals==1.7.0
nodeenv==1.9.1
numpy==2.1.1
oauth2client==4.1.3
packaging==24.1
pandas==2.2.2
passlib==1.7.4
pdfminer-six==20231228
pdfplumber==0.11.4
pillow==10.4.0
platformdirs==4.3.2
pluggy==1.5.0
ply==3.8
polyfactory==2.16.2
pre-commit==3.8.0
pretend==1.0.9
proto-plus==1.24.0
protobuf==5.28.1
pyarrow==17.0.0
pyasn1==0.6.1
pyasn1-modules==0.4.1
pycparser==2.22
pycryptodome==3.20.0
pydantic==2.9.1
pydantic-core==2.23.3
pydeck==0.9.1
pygments==2.18.0
pyjwt==2.9.0
pymupdf==1.24.10
pymupdfb==1.24.10
pyparsing==3.1.4
pypdfium2==4.30.0
pyrebase4==4.8.0
pytest==8.3.3
pytest-asyncio==0.24.0
pytest-docker==3.1.1
pytest-httpx==0.32.0
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-fity3==0.7
python-jwt==4.1.0
python-multipart==0.0.9
pytz==2024.2
pyyaml==6.0.2
referencing==0.35.1
requests==2.32.3
requests-toolbelt==0.10.1
rich==13.8.1
rpds-py==0.20.0
rsa==4.9
ruff==0.6.4
shapely==2.0.6
six==1.16.0
smmap==5.0.1
sniffio==1.3.1
st-theme==1.2.3
starlette==0.38.5
streamlit==1.38.0
streamlit-ace==0.1.1
streamlit-navigation-bar==3.3.0
svcs==24.1.0
tenacity==8.5.0
testcontainers==4.8.2
toml==0.10.2
tornado==6.4.1
typing-extensions==4.12.2
tzdata==2024.1
urllib3==1.26.20
uv==0.4.9
uvicorn==0.30.6
uvloop==0.20.0
virtualenv==20.26.4
watchfiles==0.24.0
websockets==13.0.1
wrapt==1.16.0

Things I've tried

async def test__can_run():
    compose = DockerCompose(
        compose_folder,
        compose_file_name='docker-compose.yml',
        env_file=str(Path(__file__).parents[1] / 'testing.env'),
        docker_command_path='/usr/local/bin',
    )
    with compose:
        assert True

produces:

PermissionError: [Errno 13] Permission denied: '/usr/local/bin'
async def test__can_run():
    compose = DockerCompose(
        compose_folder,
        compose_file_name='docker-compose.yml',
        env_file=str(Path(__file__).parents[1] / 'testing.env'),
        docker_command_path='/usr/local/bin/docker',
    )
    with compose:
        assert True

Produces:

E               subprocess.CalledProcessError: Command '['/usr/local/bin/docker', 'compose', '-f', 'docker-compose.yml', '--env-file', '/Users/chris.may/projects/referral_packets/tests/testing.env', 'up', '--wait']' returned non-zero exit status 15.

../../../../.pyenv/versions/3.11.9/lib/python3.11/subprocess.py:571: CalledProcessError
Chris-May-WS commented 3 hours ago

It turns out that I had an incorrect reference to my env file.

Using docker_command_path='/usr/local/bin/docker' worked.