0

I am trying to set up a small first time app in go using Docker. I want to use the cli tools for go-lang migrate. However I receive the following error:

package github.com/golang-migrate/migrate/v4/internal/cli: cannot find package "github.com/golang-migrate/migrate/v4/internal/cli" in any of: /usr/local/go/src/github.com/golang-migrate/migrate/v4/internal/cli (from $GOROOT) /go/src/github.com/golang-migrate/migrate/v4/internal/cli (from $GOPATH)

The command works fine outside of docker. I'm confused about the set up of my Dockerfile, my GOPATH appears to be fine as well.

I have a Dockerfile with the following lines:


RUN apk --update add alpine-sdk

WORKDIR $GOPATH/src/github.com/go-projects/docker-test/

RUN echo $GOPATH

RUN go get -u -d github.com/golang-migrate/migrate/cli github.com/lib/pq```
user3531263er
  • 423
  • 1
  • 4
  • 20
  • 1
    I suggest you compile in different container or on the host and only run your executable in a container which is dedicated to only execute ... also get your entire sequence of events working by manually executing them on command line and only afterwards worry about putting into containers ... trying to learn how to do both introduces unnecessary unknowns – Scott Stensland May 23 '19 at 16:55

1 Answers1

0

I was able to get this working in a Docker container with the following:

FROM golang:1.12rc1-alpine3.9 AS build  # or replace with your desired build

RUN apk --update add alpine-sdk

COPY . $GOPATH/src/github.com/go-projects/docker-test/

WORKDIR $GOPATH/src/github.com/go-projects/docker-test/

RUN echo $GOPATH

RUN go get -u -d github.com/golang-migrate/migrate github.com/lib/pq

Additionally, it is suggested to use cmd/migrate instead of cli per this commit

jonroethke
  • 1,152
  • 2
  • 8
  • 16