Run Go (golang) CLI from docker

Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Now we can run it from golang’s official docker ( ) with current terminal path.

First install Docker Engine.

curl -L | sudo bash -

Then add go run script into /usr/local/bin/go

You can custom go environment like run as user, gopath, goroot and forward port

#!/usr/bin/env bash
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
echo "Current working directory: '"$(pwd)"'"
docker run -it --rm \
--user $(id -u):$(id -g) \
--env SSH_AUTH_SOCK=/ssh-auth.sock \
-v $SSH_AUTH_SOCK:/ssh-auth.sock \
-v /etc/passwd:/etc/passwd:ro \
-v /etc/group:/etc/group:ro \
-v "$(pwd)/goroot/":/usr/local/go/src/ \
-v "$(pwd)/gopath/":/go/src/ \
-v "$(pwd)":/usr/src/myapp \
-w /usr/src/myapp \
-p 8080:8080 \
-p 8443:8443 \
zercle/docker-alpine-golang \
go "[email protected]"
exit 0

And add execute permission.

sudo chmod +x /usr/local/bin/go

Now we can use go’s cli from terminal. Test it run some command.

go version
go version
go version from docker

Kawin Viriyaprasopsook

System administrator at Zercle Technology Co., Ltd.
System admin กากๆ
ชอบดู Anime ญี่ปุ่น

Leave a Reply