Skip to content

Mongorestore fails to restore data when called from within a docker container #11

@FabianElsmer

Description

@FabianElsmer
  • py.test dockerdb version:
    0.5.1
  • Mongodb version
    3.5
  • Python version:
    2.7
  • Operating System:
    Fedora 29

Description

Dockerdb generally works even from within another docker container, as long as the docker.sock is mounted. It makes local testing a breeze, since the docker-compose / Dockerfile already encapsulates the project setup, independent of the host environment.

The restore option fails to set the data on the database when a pytest is executed from within a docker container. The dump path should exists, but the exec_run returns the following error:

('Exit code', 1, "2020-03-10T02:19:26.710+0000 Failed: mongorestore target 
'/tmp/tmpc_pieAtmp_1583806764_mongo_0/dump' invalid: stat 
/tmp/tmpc_pieAtmp_1583806764_mongo_0/dump: no such file or directory\n")

Executing the same test outside the docker container successfully restores the data. The problem seems to be related to the way the service shares data, using a shared volume. The problem can be locally reproduced but fixed by mounting /tmp in the main container.

What I Did

conftest.py

BASE_PATH = os.path.dirname(__file__)
DUMP_PATH = os.path.join(BASE_PATH, 'dump')
mongo = dockerdb.mongo_pytest.mongo_fixture(versions=["3.5"], restore=DUMP_PATH)
docker exec docker_container pytest

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