Depending on where my binary is being executed, I get different results on mgo Dial.
Right now, I'm building on my machine (Fedora: uname -a: Linux localhost.localdomain 4.15.6-300.fc27.x86_64 #1 SMP Mon Feb 26 18:43:03 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux) using the following command:
$ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s' -o myProgram
So, if I build my docker image using:
FROM centos
COPY myProgram "/usr/local/bin/myProgram"
ENTRYPOINT ["/usr/local/bin/myProgram"]
It works perfectly. That means I'm connected to the database. But, if I change to:
FROM debian
COPY myProgram "/usr/local/bin/myProgram"
ENTRYPOINT ["/usr/local/bin/myProgram"]
I'm getting no reachable servers. My goal is to compile the application on gitlab-ci using the golang image, and run it on a alpine container.
The question is: Why the same executable get different results on different base images?
Does mgo (or go) use something related to the OS? I mean, it seems that my binary will run only on red hat based distribution (just a guess, it doesn't make much sense to me right now.)
Dial source code:
dialInfo := &mgo.DialInfo{
Addrs: config.Addr,
Database: config.Auth,
Username: config.User,
Password: config.Pass,
ReplicaSetName: config.ReplicaSet,
Timeout: time.Second * 10,
}
dialInfo.DialServer = func(addr *mgo.ServerAddr) (net.Conn, error) {
return tls.Dial("tcp", addr.String(), &tls.Config{})
}
session, err := mgo.DialWithInfo(dialInfo)
if err != nil {
log.Fatal(err.Error())
}