dpmopn8542
2018-12-29 10:38
浏览 1.6k

当我与docker compose一起使用go时出现“ No Go files in ...”错误

I installed Go on Ubuntu 16.04. This is my GOPATH=/home/{username}/work.

I created a project into /home/{username}/work/src.

This is my project folder hierarchy.

project-name
   services
       configuration
           api
               main.go
           Dockerfile
       bff
           api
               main.go
           Dockerfile
   docker-compose.yml
   favicon.ico
   README.md

I can build and run with my dockerfile but I can't build and up with docker-compose.

I couldn't find any solution.

Configuration service dockerfile:

FROM golang:1.11.1-alpine3.8 as builder

RUN apk update && apk add git && go get gopkg.in/natefinch/lumberjack.v2

RUN mkdir -p /go/src/project-name/services/configuration
RUN CGO_ENABLED=0
RUN GOOS=linux
ADD . /go/src/project-name/services/configuration
ENV GOPATH /go
WORKDIR /go/src/project-name/services/configuration/api
RUN go get
RUN go build

FROM alpine
RUN apk update
RUN apk add curl

RUN mkdir -p /app
COPY --from=builder /go/src/project-name/services/configuration/api/ /app/
RUN chmod +x /app/api
WORKDIR /app
EXPOSE 5001
ENTRYPOINT ["/app/api"]

It works with dockerfile.

This is my docker-compose file:

version: '3.4'

services:
   bff:
      image: project-name/bff:${TAG:-latest}
      build:
           context: .
           dockerfile: services/bff/Dockerfile
      ports:
          - "5000:5000"
      container_name: bff 
      depends_on:
         - configuration

   configuration:
       image: project-name/configuration:${TAG:-latest}
       build:
            context: .
            dockerfile: services/configuration/Dockerfile    
       ports:
            - "5001:5001"
       container_name: configuration

It didn't work.

When the “run go get” command runs, it gives an error, the error is:

 can't load package: package project-name/services/configuration/api: no Go files in /go/src/project-name/services/configuration/api
 ERROR: Service 'configuration' failed to build: The command '/bin/sh -c go get' returned a non-zero code: 1

1条回答 默认 最新

相关推荐 更多相似问题