Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to run tests inside a docker container themselves #129

Closed
wngr opened this issue Oct 23, 2019 · 4 comments
Closed

Ability to run tests inside a docker container themselves #129

wngr opened this issue Oct 23, 2019 · 4 comments

Comments

@wngr
Copy link

wngr commented Oct 23, 2019

Hey,

the current approach of this library assumes that cargo test is executed on the host system running docker. For having a reproducible environment, it makes sense to run the tests themselves inside a docker container. To be able to have those tests spin up and access other containers, we'd need to:

  1. Be able to access the docker socket from within the container (and have docker-cli installed)
  2. Make sure the networking is properly set up, e.g. same docker network / bridging
  3. Ability to get the IP of the created container --> docker inspect has it

My proposed approach would be to create another Client and implement 2 and 3 as enumerated above. Obviously, to be able to use it, the library users needs to make sure 1 is properly set up.

What do you think about this approach? Would you be willing to accept a PR implementing the above?

@D4nte
Copy link
Contributor

D4nte commented Oct 23, 2019

Maybe look into the shiplift crate so you don't create a docker api client from scratch.

@thomaseizinger
Copy link
Collaborator

What do you think about this approach? Would you be willing to accept a PR implementing the above?

Yes definitely!
That is the direction we would want to take this library in, we just didn't have any needs for it so far :)
We would definitely accept a PR for this!

@wngr
Copy link
Author

wngr commented Oct 24, 2019

Maybe look into the shiplift crate so you don't create a docker api client from scratch.

Thanks for the hint, will give it a spin then!

wngr added a commit to wngr/testcontainers-rs that referenced this issue Dec 13, 2019
This adds the `ip_address` method to `Docker` trait in order to
to query the ip address of the spawned container. This is derived
from a `docker inspect` call.

This also introduces a new usage pattern when used from the host system:
Rather than relying on a port mapping to the host, the target port
can be directly queried by using the ip address of the container in the
internal docker network.
Note: This relies on the fact, that the default docker bridge network is
configured for all involved containers.

testcontainers#129
@DDtKey
Copy link
Collaborator

DDtKey commented May 26, 2024

I think this should be possible with current state of testcontainers. We don't use cli client anymore and there is a detection of host inside of container

So I'm going to close the issue because of outdated state, but if you feel it still doesn't work, feel free to re-open or create a new one.

Thank you!

@DDtKey DDtKey closed this as completed May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants