Sign inSign up

priyanshuksharma/go-dev-os

By priyanshuksharma

•Updated over 1 year ago

This guide explains how to use a Docker-based Go Development OS

Image
Languages & frameworks
0

129

priyanshuksharma/go-dev-os repository overview

⁠Docker Overview for Go Development OS

This guide explains how to use a Docker-based Go Development OS, which includes Golang, Git, and Vim for coding. You will learn how to build, run, and use ports for accessing applications.


⁠1. Pull the Image from Docker Hub

If the image is available on Docker Hub, pull it using:

docker pull priyanshuksharma/go-dev-os:latest

This downloads the image locally, so you don’t have to build it manually.


⁠2. Run the Container

To start the container with an interactive shell:

docker run -it --rm priyanshuksharma/go-dev-os:latest

This will drop you into a bash shell, where you can write and run Go code.


⁠3. Mount a Local Directory for Persistent Storage

By default, any files created inside a container are lost when it stops. To save your code, mount a local folder:

docker run -it --rm -v $(pwd):/workspace priyanshuksharma/go-dev-os:latest
  • This mounts your current directory inside the container at /workspace.
  • Any Go projects you create inside /workspace will be saved on your host machine.

⁠4. Expose and Use Ports

If you're running a Go web application, you need to expose ports.

⁠Run Container with a Port (Example: 8080)
docker run -it --rm -p 8080:8080 priyanshuksharma/go-dev-os:latest
  • The -p 8080:8080 flag maps port 8080 inside the container to port 8080 on your machine.
  • If your Go app runs a web server (localhost:8080), you can access it from your browser.
⁠Test a Simple Go Web Server Inside the Container

Inside the running container, create a file server.go:

nano server.go

Paste this code:

package main

import (
	"fmt"
	"net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Hello from Go in Docker!")
}

func main() {
	http.HandleFunc("/", handler)
	fmt.Println("Server running on port 8080...")
	http.ListenAndServe(":8080", nil)
}

Run it:

go run server.go

Now, open http://localhost:8080⁠ in your browser.


⁠5. Running the Container in Detached Mode

To keep the container running in the background:

docker run -d -p 8080:8080 --name go-container priyanshuksharma/go-dev-os:latest
  • The -d flag runs it in the background.
  • The --name go-container gives it a name.

To stop it later:

docker stop go-container

⁠6. Executing Commands in a Running Container

If the container is running in the background, you can access it using:

docker exec -it go-container bash

⁠7. Push Image to Docker Hub (For Future Use)

After building your image, you can push it to Docker Hub for easy access:

docker login  
docker push priyanshuksharma/go-dev-os:latest

⁠Summary of Key Commands
ActionCommand
Pull the imagedocker pull priyanshuksharma/go-dev-os:latest
Run interactive shelldocker run -it --rm priyanshuksharma/go-dev-os:latest
Mount local directorydocker run -it --rm -v $(pwd):/workspace priyanshuksharma/go-dev-os:latest
Run with portdocker run -it --rm -p 8080:8080 priyanshuksharma/go-dev-os:latest
Run in detached modedocker run -d -p 8080:8080 --name go-container priyanshuksharma/go-dev-os:latest
Stop containerdocker stop go-container
Access running containerdocker exec -it go-container bash
Push image to Docker Hubdocker push priyanshuksharma/go-dev-os:latest

⁠Next Steps
  • Extend this image with additional tools like Node.js, Python, or VS Code Server.
  • Automate deployments using Docker Compose.
  • Create a GitHub Action to build and push the image automatically.

Tag summary

Content type

Image

Digest

sha256:e29992901…

Size

243 MB

Last updated

over 1 year ago

docker pull priyanshuksharma/go-dev-os