Home > front end >  Go mod fails on Raspberry Pi Docker Compose
Go mod fails on Raspberry Pi Docker Compose

Time:01-18

When I've two microservices written in Go, each of them with their respective Dockerfile which does this

# Build
FROM golang:alpine AS build

# Destination of copy
WORKDIR /build

# Download dependencies
COPY go.mod ./
COPY go.sum ./
RUN go mod download

# Copy source code
COPY . ./

# Build
RUN go build -o bin ./cmd/main.go

# Deploy
FROM alpine

RUN adduser -S -D -H -h /app appuser
USER appuser

COPY --from=build /build/bin /app/

WORKDIR /app

EXPOSE 8080

CMD ["./bin"]

If I run docker build on them everything works fine so I made a compose.yaml file to run both microservices (and other stuff) which looks like this

services:
  redis:
    image: redis:alpine
    ports:
      - "6379:6379"
  postgres:
    image: postgres:alpine
    ports:
      - "5432:5432"
    environment:
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - ../loquegasto-backend/migrations/core.sql:/docker-entrypoint-initdb.d/1-core.sql
      - ../loquegasto-backend/migrations/core.categories.sql:/docker-entrypoint-initdb.d/2-core.categories.sql
      - ../loquegasto-backend/migrations/core.transactions.sql:/docker-entrypoint-initdb.d/3-core.transactions.sql
      - ../loquegasto-backend/migrations/core.users.sql:/docker-entrypoint-initdb.d/4-core.users.sql
      - ../loquegasto-backend/migrations/core.wallets.sql:/docker-entrypoint-initdb.d/5-core.wallets.sql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready"]
      interval: 10s
      timeout: 5s
      retries: 3
  lqg-backend:
    build: ../loquegasto-backend
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_HOST=postgres
      - POSTGRES_PORT=5432
      - JWT_SECRET=${JWT_SECRET}
      - PORT=8080
    depends_on:
      postgres:
        condition: service_healthy
  lqg-telegram:
    build: ../loquegasto-telegram
    links:
      - "redis"
      - "lqg-backend"
    environment:
      - JWT_SECRET=${JWT_SECRET}
      - TELEGRAM_TOKEN=${TELEGRAM_TOKEN}
      - BACKEND_URL=http://lqg-backend:8080
      - EXPORTER_FILE_PATH=lqg-export
      - REDIS_HOST=redis:6379
      - PORT=8080
    depends_on:
      - redis
      - lqg-backend

This runs perfect on MacOS using docker compose up --build -d but running on a Raspberry Pi 4 it always breaks when running go mod download, throwing the following message:

> [loquegasto-infra-lqg-backend build 5/7] RUN go mod download:
#0 1.623 go: github.com/Masterminds/[email protected]: Get "https://proxy.golang.org/github.com/!masterminds/squirrel/@v/v1.5.1.mod": dial tcp: lookup proxy.golang.org on [2800:810:100:1:200:115:192:28]:53: dial udp [2800:810:100:1:200:115:192:28]:53: connect: cannot assign requested address
------
failed to solve: executor failed running [/bin/sh -c go mod download]: exit code: 1

Sometimes it breaks with only one dependency, sometimes with all of them, sometimes with one ms and sometimes with the other.

Any tips?

Thanks!

CodePudding user response:

Well after some research found that my Raspberry had an empty DNS server so I set it to the Google's one (8.8.4.4 and 8.8.8.8) and worked perfectly.

Basically edited the file /etc/dhcpcd.conf, the line static domain_name_servers= to static domain_name_servers=8.8.4.4 8.8.8.8.

Thank you all!

CodePudding user response:

It seems like you are running out of available connections/sockets that the hardware is able to support. I'd try reducing GOMAXPROCS to 1 when doing go mod download like this

GOMAXPROCS=1 go mod download

[According to the Go module documentation] 1.

For example, suppose the go command is looking for a module that provides the package golang.org/x/net/html, and GOPROXY is set to https://corp.example.com,https://proxy.golang.org. The go command may make the following requests:

To https://corp.example.com/ (in parallel):

  1. Request for latest version of golang.org/x/net/html

  2. Request for latest version of golang.org/x/net

  3. Request for latest version of golang.org/x

  4. Request for latest version of golang.org

Reference - https://github.com/golang/go/issues/16012

  • Related