Skip to content

todo - run tests against docker desktop on linux #621

Open

Description

@alexanderankin

from discussion in #610

Activity

  1. changed the title [-]todo - run tests against docker desktop on windows[/-] [+]todo - run tests against docker desktop on linux[/+] on Jun 28, 2024
  2. black-snow commented on Jun 28, 2024

    @black-snow
    Contributor

    Let me know if I can assist you. Ain't got too much time to spare but I'll do my best ;)

  3. AlexElizard commented on Oct 6, 2025

    @AlexElizard

    My little research.

    Introductory:

    1. Fedora Workstation 42 x86_64
    2. Docker Desktop

    Let's look at running a basic example from the official website

    from testcontainers.postgres import PostgresContainer
    import sqlalchemy
    
    with PostgresContainer("postgres:16") as postgres:
        psql_url = postgres.get_connection_url()
        engine = sqlalchemy.create_engine(psql_url)
        with engine.begin() as connection:
            version, = connection.execute(sqlalchemy.text("SELECT version()")).fetchone()
    
    print(version)

    When DockerContainer is initialized, DockerClient is called, which gets the docker_host from tc.host in the ~/.testcontainers.properties file or from the DOCKER_HOST environment variable.

    Because of this, attempting to start fails with the error docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')).

    This problem can be solved in ~/.bashrc by setting the environment variable export DOCKER_HOST=unix://${HOME}/.docker/desktop/docker.sock or in ~/.testcontainers.properties by setting tc.host==unix://home/username/.docker/desktop/docker.sock. By the way, TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE environment does not solve the problem.

    Then we start to crash with the error docker.errors.APIError: 500 Server Error for http+docker://localhost/v1.51/containers/c57d89b2acb9f9fd4997576bdf62204daacbdfcf01006555cd0cda9e7f3624f7/start: Internal Server Error ("mounts denied: The path /socket_mnt/home/alexelizard/.docker/desktop/docker.sock is not shared from the host and is not known to Docker. You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing. See https://docs.docker.com/ for more info.")

    This is an error on startup Ryuk. I couldn't figure out where Ryuk gets the /socket_mnt.
    Using export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=${HOME}/.docker/desktop/docker.sock doesn't fix the issue with /socket_mnt.

    The solution was found in testcontainers-java #7036 - you need to set the environment variable export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=host.docker.internal.

    In summary: to run testcontainers via Docker Desktop in Fedora Workstation, you need to set the following environment variables in ~/.bashrc:

    export DOCKER_HOST=unix://${HOME}/.docker/desktop/docker.sock
    export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=host.docker.internal

    Hope this helps.

  4. kiview commented on Oct 6, 2025

    @kiview
    Member

    Btw., it's totally ok to explicitly document, that Docker Desktop for Linux is not officially supported by tc-python (we have a similar situation for the other languages, also since having DD4L on CI is very hard).

  5. AlexElizard commented on Oct 6, 2025

    @AlexElizard

    I'm not sure this is correct. Docker Desktop is quite widely used. Moreover, according to the documentation the Docker host should be detected automatically (item 6), but this doesn't happen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions