Comments (4)
I ran into this issue on Gitlab CI where you need to set the DOCKER_HOST=tcp://docker:2375
.
I ended up writing an extension trait that extends Container
with a get_host()
method. The method url parses the DOCKER_HOST
value and if scheme is ”tcp” returns the url host else returns ”localhost” (like when the scheme is ”unix”).
from testcontainers-rs.
I ran into this issue on Gitlab CI where you need to set the
DOCKER_HOST=tcp://docker:2375
.I ended up writing an extension trait that extends
Container
with aget_host()
method. The method url parses theDOCKER_HOST
value and if scheme is ”tcp” returns the url host else returns ”localhost” (like when the scheme is ”unix”).
@mchlstckl Could you please provide us some snippets of the relevant lines including the .gitlab-ci.yml? My integration tests are running fine on my local machines but not in the GitLab runner. I was struggling the past days to get this working, but I haven't figured out yet.
from testcontainers-rs.
from testcontainers-rs.
No problem, thanks for checking though. I managed to get it working and want to share it in case someone else stumbles on on this.
I am passing my docker socket to the runner as described here.
.gitlab-ci.yml:
test:
image: rust:1
stage: test
before_script:
- wget https://download.docker.com/linux/static/stable/x86_64/docker-23.0.1.tgz
- tar xvfz docker-23.0.1.tgz
- mv docker/docker /usr/bin/
- rm -Rf docker/ docker-23.0.1.tgz
script:
- cargo test
rust trait:
use std::{process::Command, io::Read, str::FromStr};
pub trait ContainerHost {
fn get_host_addr(&self) -> String;
}
impl<'d, I> ContainerHost for testcontainers::Container<'d, I>
where
I: testcontainers::Image,
{
fn get_host_addr(&self) -> String {
let mut output = String::new();
Command::new("docker")
.arg("inspect")
.arg("-f")
.arg("'{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'")
.arg(&self.id())
.output()
.expect("inspecting container")
.stdout
.as_slice()
.read_to_string(&mut output)
.expect("parsing IP address");
let output = output.replace('\'', "");
let output = String::from(output.trim());
assert!(std::net::IpAddr::from_str(output.as_str()).is_ok());
output
}
}
Then you can just connect to the container using its IP and internal port in your integration test.
from testcontainers-rs.
Related Issues (20)
- is there any way to pass "platform" parameter when running docker images? HOT 6
- Support accessing container logs HOT 15
- parallel tests hang with multiple instances of rabbit as GenericImage HOT 1
- [Question] Why would testcontainers fail to create docker network under non-root user HOT 1
- [Discussion] Reason to maintain two different implementation? HOT 1
- [Question] How to specify a newer image for Postgres HOT 2
- Supports running image with `--user` option. HOT 9
- Container doesn't stop after test with std::sync::OnceLock HOT 2
- Concurrency issue: Connection reset by peer HOT 3
- Equivalent to TestContainers.exposeHostPorts? HOT 3
- Stop containers when tests are killed HOT 1
- Feature: Retries due to periodic failure of underlying `docker` commands (ex. `rm`)? HOT 3
- Allow changing the container command HOT 1
- How to reuse containers within a test run like in Java HOT 1
- testcontainers-rs crate missing README and LICENSE files since 0.14 HOT 1
- Container::exec wait conditions are applied to logs from run command instead from exec command HOT 1
- Support overriding "command" for Image HOT 1
- How to get container host ip? HOT 3
- Can we let Docker choose a port? HOT 2
- Mapped ports are not updated after container restart HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testcontainers-rs.