Journal

Writing down the things I learned. To share them with others and my future self.

08 May 2020

Mount Local GOPATH Directory into Container

Given you have an old golang project depending on the GOPATH. You want to build that project in the golang docker image. This one liner mounts the current directory into the GOPATH of the golang image.

1
2
3
4
docker run -it \
	-w /go/src/${$(pwd)#$GOPATH/src/} \
	-v $(pwd):/go/src/${$(pwd)#$GOPATH/src/} \
	golang:1.10

Example:

1
2
3
4
5
user@host:/home/user/go/src/github.com/hikhvar/zkillbeat (git)-[master] % docker run -it \                                                               :(
        -w /go/src/${$(pwd)#$GOPATH/src/} \
        -v $(pwd):/go/src/${$(pwd)#$GOPATH/src/} \
        golang:1.10
root@5c7f5e394b2a:/go/src/github.com/hikhvar/zkillbeat# go build 

Tags