Redis: Cannot Find Package (Same as #1128)

Created on 7 Oct 2019  路  2Comments  路  Source: go-redis/redis

Pls, don't close the issue if it hasn't been solved yet :)

I'm not a docker expert so please, if this is just a config error or something that I did wrong, create a piece of documentation of how to use it properly inside docker. Thanks!

Steps

  1. create simple main.go file that uses redis
  2. create dockerfile:
FROM golang:1.8.7-alpine3.6
RUN mkdir /app
WORKDIR /app
COPY main.go /app

# get git
RUN apk update
RUN apk add git

# This here breaks
RUN go get -u github.com/go-redis/redis
RUN go build -o main .
CMD ["./main"]
  1. build (I used a docker-compose .yml and docker-compose build <name>)

Error

image

Most helpful comment

For anyone having the same problems (and cannot switch to go modules) put this in your dockerfile...

FROM golang:1.8.7-alpine3.6
RUN apk update
RUN apk add git

WORKDIR /go/src/github.com/go-redis/redis/
RUN git clone https://github.com/go-redis/redis.git .
RUN git checkout v6

WORKDIR /app
COPY main.go /app

RUN go build main.go

CMD ["./main"]

All 2 comments

You need to use Go modules that are available from v1.11 and import github.com/go-redis/redis/v7.

For anyone having the same problems (and cannot switch to go modules) put this in your dockerfile...

FROM golang:1.8.7-alpine3.6
RUN apk update
RUN apk add git

WORKDIR /go/src/github.com/go-redis/redis/
RUN git clone https://github.com/go-redis/redis.git .
RUN git checkout v6

WORKDIR /app
COPY main.go /app

RUN go build main.go

CMD ["./main"]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

zhangruiskyline picture zhangruiskyline  路  4Comments

krak3n picture krak3n  路  4Comments

Turing-Chu picture Turing-Chu  路  3Comments

aahoughton picture aahoughton  路  5Comments

mouhong picture mouhong  路  3Comments