Skip to content

Latest commit

 

History

History
34 lines (27 loc) · 794 Bytes

File metadata and controls

34 lines (27 loc) · 794 Bytes

A Better Docker compose file

version: '3.8'

services:
  my-go-app:
    # 1. "Get Golang & Git"
    # We use the official image. It comes with Go and Git pre-installed.
    image: golang:1.23
    
    # Set where we work inside the container
    working_dir: /app

    # 2. "Git clone, Tidy, Run"
    # We override the default command to run your shell sequence.
    # We use 'sh -c' to chain multiple commands together.
    command: >
      sh -c "git clone https://github.com/YOUR_USERNAME/YOUR_REPO.git . &&
      go mod tidy &&
      go run ."
    
    # Optional: Map port if your Go app is a web server
    ports:
      - "8080:8080"

To pass environment variables (if needed)

    environment:
        - MY_ENV_VAR=value
        - ANOTHER_VAR=another_value