Golang Microservices Cannot Communicate Using Docker for Mac

I am trying to get two containers, each of which launches another golang service. Both services were created with the net/http package. I have an API as one and an authentication service server.

Here is my file:

 version: "2" services: staticfiles: build: ./files volumes: - /public - /views api: build: ./api environment: - PORT=8080 - BASE_URL=https://example.org - AUTH_HOST=auth - AUTH_PORT=8080 - VIEW_DIR=/views - PUBLIC_DIR=/public ports: - "80:8080" volumes_from: - staticfiles:ro links: - auth depends_on: - staticfiles db: build: ./postgres environment: - POSTGRES_USER=inheritor - POSTGRES_DB=inheritor auth: build: ./auth expose: - "8080" environment: - PORT=8080 - DB_USER=inheritor - DB_NAME=inheritor - DB_HOST=db - DB_Port=5432 links: - db 

I know that links work because from the api container I can ping auth and curl -X Post http://auth:8080/validate , but in golang I get dial address tcp i/o timeout . Here is the golang code.

 var ( authString = "http://" + env.AuthHost + ":" + env.AuthPort ) //ValidateToken validates a token using the session in DB func ValidateToken(req *model.ValidateRequest) (*model.JWTClaims, error) { client := new(http.Client) api := authString + "/validate" cont, err := model.Jsonify(req) if err != nil { return nil, exception.NewInternalError("Could not turn the request into a json object.") } request, err := http.NewRequest("POST", api, bytes.NewBuffer(cont)) if err != nil { return nil, exception.NewInternalError("Could not create request: " + err.Error()) } request.Header.Set("Content-type", "application/json") response, err := client.Do(request) if err != nil { return nil, exception.NewInternalError("Could not make the request: " + err.Error()) } defer response.Body.Close() res := new(model.AuthResponse) res.Claims = new(model.JWTClaims) decoder := json.NewDecoder(response.Body) err = decoder.Decode(&res) spew.Dump(response.Body) if err != nil { return nil, exception.NewInternalError("Could not parse response back from auth service. " + err.Error()) } if response.StatusCode != http.StatusOK { return nil, exception.NewInvalidJWTError(res.Error) } return res.Claims, nil } 

client.Do(request) is what throws a Dial error. Now my authorization service does not even touch, because I have a registrar that displays every request that comes in.

  • env.AuthHost maps to the AUTH_HOST environment AUTH_HOST .
  • env.AuthPort maps to the Auth_PORT environment Auth_PORT .

Many thanks.

If this helps, I am running MacOSX.

 Client: Version: 1.12.0-rc4 API version: 1.24 Go version: go1.6.2 Git commit: e4a0dbc Built: Wed Jul 13 03:28:51 2016 OS/Arch: darwin/amd64 Experimental: true Server: Version: 1.12.0-rc4 API version: 1.24 Go version: go1.6.2 Git commit: e4a0dbc Built: Wed Jul 13 03:28:51 2016 OS/Arch: linux/amd64 Experimental: true 

Both golangs of the Dockerfile look like this:

 FROM golang:1.6 RUN mkdir -p /go/src/github.com/dixonwille/Inheritor/api WORKDIR /go/src/github.com/dixonwille/Inheritor/api COPY . /go/src/github.com/dixonwille/Inheritor/api RUN go build -v -o Inheritor cmd/Inheritor/main.go USER nobody ENTRYPOINT ["./Inheritor"] 

EDIT:

So, I ran net.LookupHost(env.AuthHost) in golang and it returns a different IP address, then ping , curl and even docker inspect . Is it then a golang?

EDIT:

Sorry for all the changes that try to debug when the day goes.

If I delete part of the authString port, the request will pass, but get an error while parsing the response. The answer is the 301 NGINX redirect, which, it seems to me, is strange because it is not even on my stack. The location header for localhost redirection, which, it seems to me, is also strange.

I tried to expose the port on the host machine and access it with that port without any luck (same host name).

EDIT:

So I guess only Mac. I cloned the repo and worked on Windows 10, and I was able to connect to my authorization service. Will this be a Docker for Mac bug? I'm probably going to report this to them, but I would not consider it closed, as this is still a problem for Mac users.

+6
source share
1 answer

So, Docker for Mac just came out with a new beta today. This seems to fix my connectivity issue. Now I made changes to the source code when I found out that it works on my Windows PC.

Here is the version of Docker to fix:

 Client: Version: 1.12.0 API version: 1.24 Go version: go1.6.3 Git commit: 8eab29e Built: Thu Jul 28 21:04:48 2016 OS/Arch: darwin/amd64 Experimental: true Server: Version: 1.12.0 API version: 1.24 Go version: go1.6.3 Git commit: 8eab29e Built: Thu Jul 28 21:04:48 2016 OS/Arch: linux/amd64 Experimental: true 

And here is the creation file:

 version: "2" services: staticfiles: build: ./files volumes: - /public - /views - /migrations databasefiles: build: ./databasefiles volumes: - /var/lib/postgresql/data db: build: ./postgres depends_on: - databasefiles volumes_from: - databasefiles environment: - POSTGRES_USER=inheritor - POSTGRES_DB=inheritor auth: build: ./auth expose: - "8080" depends_on: - staticfiles volumes_from: - staticfiles:ro environment: - PORT=8080 - DB_USER=inheritor - DB_NAME=inheritor - DB_HOST=db - DB_PORT=5432 - MIGRATION_DIR=/migrations links: - db api: build: ./api environment: - PORT=8080 - BASE_URL=https://example.org - AUTH_HOST=auth - AUTH_PORT=8080 - VIEW_DIR=/views - PUBLIC_DIR=/public ports: - "80:8080" volumes_from: - staticfiles:ro links: - auth depends_on: - staticfiles 

I have moved services, but I do not see anything else that could change the connection between containers. This is just here if others have the same problem.

+1
source

All Articles