Skip to content

Commit dc773ec

Browse files
committed
fix: replace localhost by 127.0.0.1
on machine with ipv6 enabled localhost is attached to an ipv4 and ipv6, and can be resolved to both => timeout ``` 127.0.0.1 localhost 127.0.1.1 dwaynebox6 ::1 ip6-localhost ip6-loopback ::1 localhost ``` (tests failed on this machine with previous code, test also failed when `::1 localhost` is commented)
1 parent 48b14c9 commit dc773ec

File tree

10 files changed

+18
-18
lines changed

10 files changed

+18
-18
lines changed

rustainers/examples/compose_custom_images.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ services:
5353
ports:
5454
- 80
5555
healthcheck:
56-
test: ["CMD", "curl", "-sf", "http://localhost"]
56+
test: ["CMD", "curl", "-sf", "http://127.0.0.1"]
5757
interval: 1s
5858
retries: 5
5959
start_period: 1s
@@ -73,7 +73,7 @@ services:
7373

7474
async fn url(&self) -> Result<String, PortError> {
7575
let port = self.nginx_port.host_port().await?;
76-
let url = format!("http://localhost:{port}");
76+
let url = format!("http://127.0.0.1:{port}");
7777

7878
Ok(url)
7979
}

rustainers/examples/custom_image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn main() -> anyhow::Result<()> {
2929

3030
// Making a dummy HTTP request
3131
let port = container.port.host_port().await?;
32-
let url = format!("http://localhost:{port}"); //DevSkim: ignore DS137138
32+
let url = format!("http://127.0.0.1:{port}"); //DevSkim: ignore DS137138
3333
Command::new("curl").args(["-v", &url]).status()?;
3434

3535
Ok(())

rustainers/src/compose/images/doc.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ services:
7272
ports:
7373
- 80
7474
healthcheck:
75-
test: ["CMD", "curl", "-sf", "http://localhost"]
75+
test: ["CMD", "curl", "-sf", "http://127.0.0.1"]
7676
interval: 1s
7777
retries: 5
7878
start_period: 1s
@@ -90,7 +90,7 @@ services:
9090
/// Build the URL of the running nginx
9191
async fn url(&self) -> Result<String, PortError> {
9292
let port = self.nginx_port.host_port().await?;
93-
let url = format!("http://localhost:{port}");
93+
let url = format!("http://127.0.0.1:{port}");
9494
9595
Ok(url)
9696
}

rustainers/src/compose/images/kafka_schema_registry/docker-compose.kraft.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
1616
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
1717
KAFKA_JMX_PORT: 9101
18-
KAFKA_JMX_HOSTNAME: localhost
18+
KAFKA_JMX_HOSTNAME: 127.0.0.1
1919
KAFKA_PROCESS_ROLES: broker,controller
2020
KAFKA_NODE_ID: 1
2121
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@kafka:29093
@@ -27,7 +27,7 @@ services:
2727
- ./kafka_update_run.sh:/tmp/update_run.sh
2828
command: 'bash -c ''if [ ! -f /tmp/update_run.sh ]; then echo "ERROR: Did you forget the update_run.sh file that came with this docker-compose.yml file?" && exit 1 ; else /tmp/update_run.sh && /etc/confluent/docker/run ; fi'''
2929
healthcheck:
30-
test: ["CMD", "nc", "-z", "localhost", "9092"]
30+
test: ["CMD", "nc", "-z", "127.0.0.1", "9092"]
3131
interval: 5s
3232
retries: 20
3333
start_period: 8s
@@ -44,7 +44,7 @@ services:
4444
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: kafka:9093
4545
SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:8081 #Devskim: ignore DS137138
4646
healthcheck:
47-
test: ["CMD", "curl", "--fail", "http://localhost:8081/subjects"] #Devskim: ignore DS137138
47+
test: ["CMD", "curl", "--fail", "http://127.0.0.1:8081/subjects"] #Devskim: ignore DS137138
4848
interval: 1s
4949
retries: 20
5050
start_period: 8s

rustainers/src/compose/images/kafka_schema_registry/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl KafkaSchemaRegistry {
6969
/// Fail if we cannot retrieve the Kafka host port
7070
pub async fn broker_address(&self) -> Result<String, PortError> {
7171
let port = self.kafka_port.host_port().await?;
72-
let addr = format!("localhost:{port}");
72+
let addr = format!("127.0.0.1:{port}");
7373

7474
Ok(addr)
7575
}
@@ -81,7 +81,7 @@ impl KafkaSchemaRegistry {
8181
/// Fail if we cannot retrieve the schema registry host port
8282
pub async fn schema_registry_endpoint(&self) -> Result<String, PortError> {
8383
let port = self.schema_registry_port.host_port().await?;
84-
let addr = format!("http://localhost:{port}");
84+
let addr = format!("http://127.0.0.1:{port}");
8585

8686
Ok(addr)
8787
}

rustainers/src/compose/images/redpanda/docker-compose.single.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ services:
1717
# from inside the same Docker network.
1818
# Use the external addresses to connect to the Redpanda brokers'
1919
# from outside the Docker network.
20-
- --advertise-kafka-addr internal://redpanda-0:9092,external://localhost:19092
20+
- --advertise-kafka-addr internal://redpanda-0:9092,external://127.0.0.1:19092
2121
- --pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082
2222
# Address the broker advertises to clients that connect to the HTTP Proxy.
23-
- --advertise-pandaproxy-addr internal://redpanda-0:8082,external://localhost:18082
23+
- --advertise-pandaproxy-addr internal://redpanda-0:8082,external://127.0.0.1:18082
2424
- --schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081
2525
# Redpanda brokers use the RPC API to communicate with eachother internally.
2626
- --rpc-addr redpanda-0:33145

rustainers/src/compose/images/redpanda/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Redpanda {
7474
/// Fail if we cannot retrieve the Kafka host port
7575
pub async fn broker_address(&self) -> Result<String, PortError> {
7676
let port = self.redpanda_port.host_port().await?;
77-
let addr = format!("localhost:{port}");
77+
let addr = format!("127.0.0.1:{port}");
7878

7979
Ok(addr)
8080
}
@@ -86,7 +86,7 @@ impl Redpanda {
8686
/// Fail if we cannot retrieve the schema registry host port
8787
pub async fn schema_registry_endpoint(&self) -> Result<String, PortError> {
8888
let port = self.schema_registry_port.host_port().await?;
89-
let addr = format!("http://localhost:{port}");
89+
let addr = format!("http://127.0.0.1:{port}");
9090

9191
Ok(addr)
9292
}

rustainers/src/images/doc.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl ToRunnableContainer for Nginx {
5555
// Note that this command is executed in the container
5656
// therefore you need to have the `curl` command available in the container
5757
HealthCheck::builder()
58-
.with_command("curl -sf http://localhost") //DevSkim: ignore DS137138
58+
.with_command("curl -sf http://127.0.0.1") //DevSkim: ignore DS137138
5959
.build(),
6060
)
6161
// ports mapping
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{"Command":"\"/bin/sh -c 'echo \\\"$CONSOLE_CONFIG_FILE\\\" \u003e /tmp/config.yml; /app/console'\"","CreatedAt":"2023-10-31 08:09:58 +0100 CET","ID":"efb522e2ce2be08d3ff96685c07dd6521c27ddb2aac2c33761f292a74dd872d0","Image":"docker.redpanda.com/redpandadata/console:v2.3.1","Labels":"com.docker.compose.config-hash=3296331ac9fc28f502ae8d441a01bdda377ddf205f52ffd127ae380015c64238,com.docker.compose.container-number=1,com.docker.compose.depends_on=redpanda-0:service_started:false,com.docker.compose.image=sha256:f800e7e38f136f21ea355d182bc410ce41887bc2198c73b8305f7bd693db45f9,com.docker.compose.project.config_files=/private/var/folders/2x/tdn33dyd1tz5nwv_g_sht294bq9pmc/T/tc_redpanda-single_01HE292MFVNRVNXGTS4ZD3J6H9/docker-compose.yaml,com.docker.compose.service=console,com.docker.compose.version=2.23.0,com.docker.compose.oneoff=False,com.docker.compose.project=tc_redpanda-single_01he292mfvnrvnxgts4zd3j6h9,com.docker.compose.project.working_dir=/private/var/folders/2x/tdn33dyd1tz5nwv_g_sht294bq9pmc/T/tc_redpanda-single_01HE292MFVNRVNXGTS4ZD3J6H9","LocalVolumes":"0","Mounts":"","Names":"redpanda-console","Networks":"tc_redpanda-single_01he292mfvnrvnxgts4zd3j6h9_redpanda_network","Ports":"","RunningFor":"3 hours ago","Size":"0B","State":"exited","Status":"Exited (0) 54 minutes ago"}
2-
{"Command":"\"/entrypoint.sh redpanda start '--kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092' '--advertise-kafka-addr internal://redpanda-0:9092,external://localhost:19092' '--pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082' '--advertise-pandaproxy-addr internal://redpanda-0:8082,external://localhost:18082' '--schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081' '--rpc-addr redpanda-0:33145' '--advertise-rpc-addr redpanda-0:33145' '--smp 1' '--memory 1G' '--mode dev-container' --default-log-level=debug\"","CreatedAt":"2023-10-31 08:09:58 +0100 CET","ID":"58e4e6921c09b9ad17e62ae6fa92455bbe69eca31782b7b848b3972b86af1eb7","Image":"docker.redpanda.com/redpandadata/redpanda:v23.2.14","Labels":"com.docker.compose.version=2.23.0,com.docker.compose.config-hash=031c12f72e210164448c0953355f027f56940e1b5abed6007bf3a76fe2df1a25,com.docker.compose.container-number=1,com.docker.compose.depends_on=,com.docker.compose.oneoff=False,com.docker.compose.project=tc_redpanda-single_01he292mfvnrvnxgts4zd3j6h9,com.docker.compose.project.working_dir=/private/var/folders/2x/tdn33dyd1tz5nwv_g_sht294bq9pmc/T/tc_redpanda-single_01HE292MFVNRVNXGTS4ZD3J6H9,com.docker.compose.service=redpanda-0,org.opencontainers.image.authors=Redpanda Data \[email protected]\u003e,com.docker.compose.image=sha256:88b9c19ba78ef1322be5e86be8d3bb1b7231b62d1e0cb3c5e02b60046d16bdd6,com.docker.compose.project.config_files=/private/var/folders/2x/tdn33dyd1tz5nwv_g_sht294bq9pmc/T/tc_redpanda-single_01HE292MFVNRVNXGTS4ZD3J6H9/docker-compose.yaml","LocalVolumes":"1","Mounts":"tc_redpanda-single_01he292mfvnrvnxgts4zd3j6h9_redpanda-0","Names":"redpanda-0","Networks":"tc_redpanda-single_01he292mfvnrvnxgts4zd3j6h9_redpanda_network","Ports":"","RunningFor":"3 hours ago","Size":"0B","State":"exited","Status":"Exited (0) 54 minutes ago"}
2+
{"Command":"\"/entrypoint.sh redpanda start '--kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092' '--advertise-kafka-addr internal://redpanda-0:9092,external://127.0.0.1:19092' '--pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082' '--advertise-pandaproxy-addr internal://redpanda-0:8082,external://127.0.0.1:18082' '--schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081' '--rpc-addr redpanda-0:33145' '--advertise-rpc-addr redpanda-0:33145' '--smp 1' '--memory 1G' '--mode dev-container' --default-log-level=debug\"","CreatedAt":"2023-10-31 08:09:58 +0100 CET","ID":"58e4e6921c09b9ad17e62ae6fa92455bbe69eca31782b7b848b3972b86af1eb7","Image":"docker.redpanda.com/redpandadata/redpanda:v23.2.14","Labels":"com.docker.compose.version=2.23.0,com.docker.compose.config-hash=031c12f72e210164448c0953355f027f56940e1b5abed6007bf3a76fe2df1a25,com.docker.compose.container-number=1,com.docker.compose.depends_on=,com.docker.compose.oneoff=False,com.docker.compose.project=tc_redpanda-single_01he292mfvnrvnxgts4zd3j6h9,com.docker.compose.project.working_dir=/private/var/folders/2x/tdn33dyd1tz5nwv_g_sht294bq9pmc/T/tc_redpanda-single_01HE292MFVNRVNXGTS4ZD3J6H9,com.docker.compose.service=redpanda-0,org.opencontainers.image.authors=Redpanda Data \[email protected]\u003e,com.docker.compose.image=sha256:88b9c19ba78ef1322be5e86be8d3bb1b7231b62d1e0cb3c5e02b60046d16bdd6,com.docker.compose.project.config_files=/private/var/folders/2x/tdn33dyd1tz5nwv_g_sht294bq9pmc/T/tc_redpanda-single_01HE292MFVNRVNXGTS4ZD3J6H9/docker-compose.yaml","LocalVolumes":"1","Mounts":"tc_redpanda-single_01he292mfvnrvnxgts4zd3j6h9_redpanda-0","Names":"redpanda-0","Networks":"tc_redpanda-single_01he292mfvnrvnxgts4zd3j6h9_redpanda_network","Ports":"","RunningFor":"3 hours ago","Size":"0B","State":"exited","Status":"Exited (0) 54 minutes ago"}
33
{"Command":"\"/hello\"","CreatedAt":"2023-10-31 07:46:29 +0100 CET","ID":"4133b65cffa94eb08caefba96e8182e119efccd9655d3230365bc73b0a6e109e","Image":"hello-world","Labels":"","LocalVolumes":"0","Mounts":"","Names":"trusting_antonelli","Networks":"bridge","Ports":"","RunningFor":"3 hours ago","Size":"0B","State":"exited","Status":"Exited (0) 2 hours ago"}

rustainers/tests/common/images.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl ToRunnableContainer for InternalWebServer {
1919
.with_image(ImageName::new("docker.io/nginx"))
2020
.with_wait_strategy(
2121
HealthCheck::builder()
22-
.with_command("curl -sf http://localhost") //DevSkim: ignore DS137138
22+
.with_command("curl -sf http://127.0.0.1") //DevSkim: ignore DS137138
2323
.build(),
2424
)
2525
.build()
@@ -91,7 +91,7 @@ impl WebServer {
9191
/// Fail if we cannot retrieve the result
9292
pub async fn get(&self, path: &str) -> anyhow::Result<String> {
9393
let port = self.0.host_port().await?;
94-
let url = format!("http://localhost:{port}/{}", path.trim_start_matches('/')); //DevSkim: ignore DS137138
94+
let url = format!("http://127.0.0.1:{port}/{}", path.trim_start_matches('/')); //DevSkim: ignore DS137138
9595
let out = Command::new("curl").arg(&url).output()?;
9696
let result = String::from_utf8_lossy(&out.stdout);
9797
Ok(result.to_string())

0 commit comments

Comments
 (0)