1 / 1
Aug 2024

I have a docker container hosted on Koyeb: https://www.koyeb.com/ that contains rust code to be built & then run the release binary as API server.
Also, whitelisted the IP Address of the App url in the “Network Access” in mongoDB. I am using M0 cluster.

Dockerfile:

# ================================ # Stage 1: Build the Rust project # ================================ FROM rust:1.80.1-slim-bullseye AS builder # Install required dependencies for building OpenSSL RUN apt-get update && apt-get install -y \ pkg-config \ libssl-dev \ && rm -rf /var/lib/apt/lists/* # Set the working directory inside the container WORKDIR /usr/src/app # Copy the source code into the container COPY . . # Build the project (assuming the binary is named 'op-api-service') RUN cargo build --release -p op-api-service # ================================ # Stage 2: Create the final image # ================================ FROM debian:buster-slim # Install required libraries for running OpenSSL RUN apt-get update && apt-get install -y \ libssl1.1 \ openssl \ ca-certificates \ && rm -rf /var/lib/apt/lists/* # Optional: Check the SSL connection to MongoDB Atlas # RUN openssl s_client -tls1_2 -connect ac-xdtjxkm-shard-00-00.xrlfvc5.mongodb.net:27017 -servername ac-xdtjxkm-shard-00-00.xrlfvc5.mongodb.net -debug || \ # (echo "SSL connection to MongoDB failed"; exit 1) # RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf && \ # echo "nameserver 8.8.4.4" >> /etc/resolv.conf # CMD sh -c "openssl s_client -tls1_2 -connect ac-xdtjxkm-shard-00-00.xrlfvc5.mongodb.net:27017 -servername ac-xdtjxkm-shard-00-00.xrlfvc5.mongodb.net" # Copy the compiled binary from the builder stage COPY --from=builder /usr/src/app/target/release/op-api-service /op-api-service # Set the command to run the binary with the environment variable CMD ["sh", "-c", "RUST_LOG=info /op-api-service"]

I tried with 3 mongodb URI as env variable:
a. “mongodb+srv://user123:xxxxxxxxx@cluster0.xrlfvc5.mongodb.net/”
b. “mongodb+srv://user123:xxxxxxxxx@cluster0.xrlfvc5.mongodb.net/?retryWrites=true&w=majority&tls=true”
c. “mongodb://user123:xxxxxxxxx@cluster0.xrlfvc5.mongodb.net/?retryWrites=true&w=majority&tls=true&connectTimeoutMS=30000&socketTimeoutMS=30000”

But, still same issue:

Error: Kind: Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: cluster0.xrlfvc5.mongodb.net:27017, Type: Unknown, Error: Kind: I/O error: failed to lookup address information: No address associated with hostname, labels: {} } ] }, labels: {}

Need to fix this. Any idea what am I missing?