2
respostas

Problema com o docker-compose de uma API em GO

Ao utilizar o docker-compose up -d acontece o erro:

panic: html/template: pattern matches no files: templates/*

goroutine 1 [running]: html/template.Must(...) /usr/local/go/src/html/template/template.go:374 github.com/gin-gonic/gin.(*Engine).LoadHTMLGlob(0xc000083380, {0xba57d4, 0xb}) /go/pkg/mod/github.com/gin-gonic/gin@v1.7.7/gin.go:225 +0x2e6 github.com/guilhermeonrails/api-go-gin/routes.HandleRequest() /app/routes/route.go:10 +0x33 main.main() /app/main.go:10 +0x1c

Esse seria o código do docker-compose https://github.com/GiancarloHa/api_rest_gin_go_2-validacoes-e-testes/tree/main/compose

Dockerfile: https://github.com/GiancarloHa/api_rest_gin_go_2-validacoes-e-testes/blob/main/Dockerfile

Aplicação: https://github.com/GiancarloHa/api_rest_gin_go_2-validacoes-e-testes

2 respostas

Oi, Giancarlo. Tudo bem?

Esse erro acontece na execução do docker compose up -d? Estranho, pois no docker-compose.yml não tem nada que se refira ao build ou execução da aplicação Go. Certeza que é ap

Realizei alterações tanto no dockerfile como no docker-compose, utilizando o docker-compose --build -d ainda continuo tendo o mesmo erro.

Dockerfile

FROM golang:1.19.3-alpine as builder
RUN apk update && apk add --no-cache git
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
FROM alpine:3.17
RUN apk --no-cache add ca-certificates
WORKDIR /root/
COPY --from=builder /app/main .
ENV HOST=localhost DBPORT=5432
ENV USER=root PASSWORD=root DBNAME=root
ENV GIN_MODE=release
EXPOSE 8080
CMD ["./main"]

Docker-compose

version: '3'

networks:
  app_net:
    driver: bridge

services:
  postgres:
    container_name: db
    image: "postgres"
    environment:
      - POSTGRES_USER=root
      - POSTGRES_PASSWORD=root
      - POSTGRES_DB=root      
    ports:
      - "5432:5432"
    volumes:
      - /postgres-data:/var/lib/postgresql/data
    networks:
      - app_net 
  pgadmin-compose:
    container_name: pgadm
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: "gui@alura.com"
      PGADMIN_DEFAULT_PASSWORD: "123456"
    ports:
      - "54321:80"
    depends_on:
      - postgres
    networks:
      - app_net
  golang:
    build: .
    container_name: app
    depends_on:
      - postgres
    ports:
      - "8080:8080"
    networks:
      - app_net
    environment:
      - USER=root
      - HOST=postgres
      - PORT=5432
      - PASSWORD=root
      - DBNAME=root