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 ( https://hub.docker.com/_/golang/ ) with current terminal path.
First install Docker Engine.
curl -L https://get.docker.com | sudo bash -
Then add go run script into /usr/local/bin/go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 \ | |
-v "$(pwd)":/usr/src/myapp \ | |
-w /usr/src/myapp \ | |
golang:alpine \ | |
go "[email protected]" | |
exit 0 |
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/github.com":/usr/local/go/src/github.com \ -v "$(pwd)/gopath/github.com":/go/src/github.com \ -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 exit
Now we can use go’s cli from terminal. Test it run some command.
go version

- Convert flac audio to opus/ogg/mp3 - 2020-12-20
- Fix systemd resolved not working (127.0.0.53) - 2019-09-23
- Safely remove SATA disk from a running Linux system - 2019-05-24