-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5964994
commit 3bf0e0b
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use reqwest::blocking::Client; | ||
use reqwest::Url; | ||
use std::os::unix::net::UnixStream; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// Create a Unix stream connected to the Docker socket | ||
let socket_path = "/var/run/docker.sock"; | ||
let stream = match UnixStream::connect(socket_path) { | ||
Ok(sock) => sock, | ||
Err(e) => { | ||
println!("Couldn't connect: {e:?}"); | ||
return Ok(()); | ||
} | ||
}; | ||
|
||
// Emulate this | ||
// curl --unix-socket /var/run/docker.sock -X GET http:/v1.45/containers/json | ||
|
||
// Create a reqwest client with the Unix stream as the connector | ||
let client = Client::builder().build().unwrap(); | ||
|
||
// Make the GET request to the specified endpoint | ||
let url = Url::parse("http://localhost/v1.45/containers/json")?; | ||
let response = client.get(url).send()?; | ||
|
||
// Check the response status and print the response body | ||
if response.status().is_success() { | ||
let body = response.text()?; | ||
println!("Response Body: {}", body); | ||
} else { | ||
println!("Request failed with status: {}", response.status()); | ||
} | ||
|
||
Ok(()) | ||
} |