Mongodb Atlas connect with docker app golang

My whole application already dockerize & I want to add mogodb database in our project. here is following code

serverAPIOption := options.ServerAPI(options.ServerAPIVersion1)
clientOptions := options.Client().ApplyURI(“mongodb+srv://”).

client, err := mongo.NewClient(clientOptions)
if err != nil {
log.Fatalln(“Error create client object :”, err)
return &mongo.Client{}

docker run --rm --hostname=wizdwarfs --net=host -p -v app:/app/app_data -it v0b

2022/05/12 12:16:11 Error create client object : error parsing uri: lookup on cannot unmarshal DNS message, Please help. --net=host allow you to connect with internet; either this cause by docker or some technical issue

Hi @Ali_Hassan1 - Welcome to the community!

The above error message could possibly be caused by to what is detailed on More specifically, I would refer to the following comment on March 15 which provides more information on the possible causes and a solution / workaround.

If you still require additional assistance, please:

  1. Replace the DNS Seed List Connection Format (beginning with "mongodb+srv://") with the Standard Connection String Format (beginning with "mongodb://") and advise if the error message is still present. Please provide the full error message once this is attempted.
  2. Advise the MongoDB Go driver version
  3. Advise the Go language version
  4. Attempt to connect from outside the docker environment using the same connection string and advise if you are able to connect.


1 Like

Thanks … Some day I will try but currently I’m very busy in different project

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.