skip to Main Content

Error While Building Docker Compose!!

[orders 7/7] RUN go build *.go:
0.359 main.go:9:2: no required module provides package github.com/dojeto/order-management-system/common; to add it:
0.359 go get github.com/dojeto/order-management-system/common
0.359 grpc_handler.go:7:2: no required module provides package github.com/dojeto/order-management-system/common/api; to add it:
0.359 go get github.com/dojeto/order-management-system/common/api


failed to solve: process "/bin/sh -c go build *.go" did not complete successfully: exit code: 1

DockerFile :

FROM golang:1.22

WORKDIR /app

COPY go.mod go.mod

COPY go.sum go.sum

RUN go mod download

COPY . .

RUN go build *.go

ENTRYPOINT [ "./main" ]

Docker Compose File:

version: '3.8'

services:
  mongodb:
    container_name: mongodb
    image: mongo
    networks:
      - my-network
    ports:
      - '27017:27017'
    volumes:
      - ./common:/app/common

  orders:
    container_name: orders
    build: 
      context: ./orders
      dockerfile: Dockerfile
    networks:
      - my-network
    depends_on:
      - mongodb
    volumes:
      - ./common:/app/common

  gateway:
    container_name: gateway
    ports:
      - '8080:8080'
    build:
      context: ./gateway
      dockerfile: Dockerfile
    networks:
      - my-network
    volumes:
      - /home/dojeto/Projects/MicroServices/common:/app/common
      
networks:
  my-network:
    driver: bridge

volumes:
  dbdata6:

File Structure

Gateway and order service is using common file but as both the service have separate Dockerfile for them unable to locate common module
how can i fix this issue any suggestion !?

I want to use common folder in both the container so both service can work properly ….

2

Answers


  1. It seems like there might be an error in building the image, not just starting it. To address this, you should ensure all necessary files are in accessible locations (also the mentioned modules in the error message) and try building your image beforehand.

    Login or Signup to reply.
  2. Without looking at code it’s an assumption, but judging by the symptoms it may be related to differences between your local OS and a variant of Linux, where you build.

    E.g. if you are on Win, which is case insensitive, build may fail due to case sensitivity of the Linux. Check that module path has consistent letter case across the whole project.

    Module path is what you specified in go.mod after module.

    For example:

    in go.mod:  module example.com/foo/bAr
    in main.go: import example.com/foo/bar
    

    will lead to this error on Linux (thus, during a build in Docker as well).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search