简体   繁体   中英

Docker compose $GOPATH/go.mod exists but should not

I have a Dockerfile that runs perfectly on it's own.

But when I run it from docker-compose up --build

I get: $GOPATH/go.mod exists but should not

Below is a snippet of terminal output.

Successfully tagged app_app:latest
Starting golang_db ... done
Starting golang_app ... done
Attaching to golang_db, golang_app
golang_app | $GOPATH/go.mod exists but should not
.
.
golang_db | Version: '5.6.48'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
golang_app exited with code 1

Any suggestions?

#docker-compose.yml
version: '3'
services:
  db:
    build:
      context: ./MySQL
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: test_db
      MYSQL_USER: docker
      MYSQL_PASSWORD: docker
    container_name: golang_db
    ports:
      - "3306:3306"
    tty: true
  app:
    build:
      context: ./Go
    volumes:
      - "./Go:/go"
    container_name: golang_app
    ports:
      - "9000:9000"
    tty: true
    depends_on:
      - db
#Go/Dockerfile
FROM golang:alpine AS builder
ENV GO111MODULE=on
RUN mkdir /app
ADD . /app/
WORKDIR /app
COPY ./structs.go .
COPY ./handlers.go .
COPY ./server.go .
COPY ./favicon.ico .
COPY ./assets /assets
RUN go mod init stuff.com
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build $(ls -1 *.go)
EXPOSE 9000
CMD ["go", "run", "."]
#MySQL/Dockerfile
FROM mysql:5.6
COPY test.sql /docker-entrypoint-initdb.d/test.sql

In the root of your GOPATH no packages are expected. The expectation is usually to have a subdirectory src/github.com/someproject/somerepo, which is most likely the root cause of the warning

I sorted it out, the Dockerfile above has been updated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM