I got an error
go: open /go/src/dummy/go.mod: permission denied
when i try to execute any go command in Docker (go get, go list etc.)
OS:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic
docker:
$ docker -v
Docker version 19.03.6, build 369ce74a3c
image: golang:1.13.3-alpine3.10
to illustrate this, I created a dummy project
main.go:
package main
import (
"fmt"
)
func main() {
fmt.Print("this file is not important for question")
}
Dockerfile:
FROM golang:1.13.3-alpine3.10 as builder
WORKDIR /go/src/dummy
COPY . .
RUN go list
CMD tail -f /dev/null
and empty files go.mod and go.sum, so now project dir is:
$ ls -l
-rw-r--r-- 1 curuser curuser 139 may 23 15:03 Dockerfile
-rw-r--r-- 1 curuser curuser 22 may 23 15:03 go.mod
-rw-r--r-- 1 curuser curuser 0 may 23 14:48 go.sum
-rw-r--r-- 1 curuser curuser 86 may 23 14:50 main.go
Build image, and i got:
$ docker build -t dummy ~/go/src/dummy
Sending build context to Docker daemon 4.608kB
Step 1/5 : FROM golang:1.13.3-alpine3.10 as builder
---> f23ef2e47d30
Step 2/5 : WORKDIR /go/src/dummy
---> Running in 0e276917d658
Removing intermediate container 0e276917d658
---> e9e910dd0ccd
Step 3/5 : COPY . .
---> 19230669ad27
Step 4/5 : RUN go list
---> Running in faefa6d5930e
go: open /go/src/dummy/go.mod: permission denied
The command '/bin/sh -c go list' returned a non-zero code: 1
Now I change a Dockerfile to stay alive (comment line 4 : # RUN go list) so I can build and run image
$ docker build -t dummy ~/go/src/dummy
....
Successfully built 385e0629e67f
Successfully tagged dummy:latest
then I run sh in docker, and get permissions of copied files:
$ docker exec -it 6da5ca617c4d sh
#-----now we in the docker-----
/go/src/dummy # ls -l
total 12
-rw-r--r-- 1 root root 108 May 23 12:15 Dockerfile
-rw-r--r-- 1 root root 22 May 23 12:03 go.mod
-rw-r--r-- 1 root root 0 May 23 11:48 go.sum
-rw-r--r-- 1 root root 86 May 23 11:50 main.go
But even if i change now permissions for go.mod to 777 i still got the same error:
#-----in the docker-----
/go/src/dummy # chmod 777 go.mod
/go/src/dummy # go list
go: open /go/src/dummy/go.mod: permission denied
Same isssue on other versions of golang image (golang:1.13.11-alpine3.11 , 1.14.3-alpine3.11 etc.)
Same issue reproduces on real project, so I can't execute go get, go list etc. in docker.
Previously, everything worked fine, but at some moment (22.05.2020) this error appears without any changes in files or configuration
Please, help
The colution was a complete reinstall of docker. After reinstall (same version 19.03.6) all works fine. Unfortunately, i could not find the reason and any other way to solve this problem.