{"id":20199323,"url":"https://github.com/mwiater/golangdocker","last_synced_at":"2026-02-15T10:02:39.333Z","repository":{"id":65390611,"uuid":"568181424","full_name":"mwiater/golangdocker","owner":"mwiater","description":"Building a Docker container for Golang binaries. Includes Fiber Rest API, tests, K8s integration...","archived":false,"fork":false,"pushed_at":"2023-10-10T18:43:06.000Z","size":8553,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-10T11:34:38.585Z","etag":null,"topics":["docker","golang","kubernetes"],"latest_commit_sha":null,"homepage":"https://mwiater.github.io/golangdocker/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mwiater.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-19T17:50:31.000Z","updated_at":"2024-02-25T08:22:43.000Z","dependencies_parsed_at":"2024-06-21T18:08:24.086Z","dependency_job_id":null,"html_url":"https://github.com/mwiater/golangdocker","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mwiater/golangdocker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwiater%2Fgolangdocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwiater%2Fgolangdocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwiater%2Fgolangdocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwiater%2Fgolangdocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwiater","download_url":"https://codeload.github.com/mwiater/golangdocker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwiater%2Fgolangdocker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29475317,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T06:58:05.414Z","status":"ssl_error","status_checked_at":"2026-02-15T06:58:05.085Z","response_time":118,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","golang","kubernetes"],"created_at":"2024-11-14T04:37:05.584Z","updated_at":"2026-02-15T10:02:39.289Z","avatar_url":"https://github.com/mwiater.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Golangdocker\n\n| ![\"Go\"](_repository_assets/logo-golang.png?raw=true \"Go\") | ![\"Docker\"](_repository_assets/logo-docker.png?raw=true \"Docker\") | ![\"Fiber\"](_repository_assets/logo-golang-fiber.png?raw=true \"Fiber\") | ![\"Kubernetes\"](_repository_assets/logo-k8s.png?raw=true \"Kubernetes\") |\n|:-------------:|:-------------:|:-------------:|:-------------:|\n\n## Documentation\n\n**Start here:** [Extensive project documentation is here.](https://mwiater.github.io/golangdocker/)\n\n**Bonus:** For information on how this project relates to the \u003cstrong\u003e12-factor-app methodology\u003c/strong\u003e, see my article: [Creating a compiled Golang binary for use in a minimal Docker container as defined by the 12 Factor App methodology](https://medium.com/dev-genius/creating-a-compiled-golang-binary-for-use-in-a-minimal-docker-container-ae1c5a720aab)\n\t\t\t\u003c/div\u003e\n\n\u003chr\u003e\n\n## Setup/Install\n\n### Requirements\n\n* Go: https://go.dev/learn/\n* Docker: https://www.docker.com/get-started/\n\n#### My development environment:\n\n* `more /etc/os-release`: \u003cstrong\u003eUbuntu 20.04.5 LTS\u003c/strong\u003e\n* `go version`: \u003cstrong\u003ego1.21.2 linux/amd64\u003c/strong\u003e\n* `docker -v`: \u003cstrong\u003eDocker version 24.0.6, build ed223bc\u003c/strong\u003e\n\n#### Simple\n\n```\ngit clone git@github.com:mwiater/golangdocker.git\ncd golangdocker\ngo mod tidy\ngo install github.com/swaggo/swag/cmd/swag@latest\ngo install golang.org/x/tools/cmd/godoc\ngo install gotest.tools/gotestsum@latest\ncurl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.2\n```\n\n#### Preferred: Anaconda\n\n* Follow setup for your system here: https://docs.anaconda.com/anaconda/install/\n* Anaconda distributions: https://www.anaconda.com/products/distributio\n\nOnce installed, you'll also need a compiler for your system, e.g. for Ubuntu: `conda install gxx_linux-64`\n\nCreate the environment: `conda create -c conda-forge -n golangdocker go`\n\nVerify: `conda info --envs`\n\n```\n# conda environments:\n#\nbase                     /home/matt/anaconda3\ngolangdocker             /home/matt/anaconda3/envs/golangdocker\n```\n\nActivate: `conda activate golangdocker`\n\n```\ngit clone git@github.com:mwiater/golangdocker.git\ncd golangdocker\ngo mod tidy\ngo install github.com/swaggo/swag/cmd/swag@latest\ngo install golang.org/x/tools/cmd/godoc\ngo install gotest.tools/gotestsum@latest\ncurl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.51.2\n```\n\nWhen you're finished with the environment, you can deactivate it: `conda deactivate`\n\nOr, remove it completely: `conda env remove -n golangdocker`\n\n\u003chr\u003e\n\n## Application\n\nFor convenience, I've included a makefile. Just type `make` to see all of the targets (comments added for clarity):\n\n```\nTargets in this Makefile:\n\nmake docker-build          // Build the golang binary in the docker container\nmake docker-run            // Run the docker container\nmake docker-run-multi      // Run 2 instances of the docker container on different ports\nmake golang-build          // Build the golang binary into: ./bin\nmake golang-build-arm64    // Build an example golang binary in a different architecture into: ./bin\nmake golang-godoc          // Generate and run GoDoc server, port 6060\nmake golang-lint           // Lint the application\nmake golang-run            // Run the application, no compilation\nmake golang-test           // Run the tests\n\nFor details on these commands, see the bash scripts in the 'scripts/' directory.\n```\n\n**NOTE:** Many of the bash scripts execute helpers before the main command, e.g.: `swag init`, `gofmt`, etc. There are exit status checks in place so that, for example, if `gofmt` fails prior to the build (usually because of a syntax error), the script will report the error and exit before trying to build the go binary--which would likely fail due to theerror found via `gofmt`. Here is an example of the script pattern:\n\n```\n...\necho -e \"${CYANBOLD}Building Swagger docs...${RESET}\"\nswag init\nstatus=$?\nif test $status -ne 0\nthen\n\techo -e \"${REDBOLD}...Error: 'swag init' command failed:${RESET}\"\n\techo \"\"\n\texit 1\nfi\necho -e \"${GREENBOLD}...Complete.${RESET}\"\necho \"\"\n\necho -e \"${CYANBOLD}Formatting *.go files...${RESET}\"\nfor i in *.go **/*.go ; do\n\tgofmt -w \"$i\"\n\tstatus=$?\n\tif test $status -ne 0\n\tthen\n\t\techo -e \"${REDBOLD}...Error: 'gofmt' command failed!${RESET}\"\n\t\techo \"\"\n\t\texit 1\n\tfi\n\techo \"Formatted: $i\"\ndone;\necho -e \"${GREENBOLD}...Complete${RESET}\"\necho \"\"\n...\n```\n\n### Basic run, without compilation\n\nCommand line: `go run .`\n\nor via the Makefile: `make golang-run`\n\nOutput will be similar to:\n\n```\n ┌───────────────────────────────────────────────────┐\n │                   Fiber v2.40.1                   │\n │               http://127.0.0.1:5000               │\n │       (bound on host 0.0.0.0 and port 5000)       │\n │                                                   │\n │ Handlers ............ 22  Processes ........... 1 │\n │ Prefork ....... Disabled  PID ............ 783295 │\n └───────────────────────────────────────────────────┘\n```\n\nAnd will be accessible at: `http://{your-host-ip-address}:5000/`\n\nThe above base URL will have the following endpoints, where anything under the `resource` path will return current system information, and other endpoints provide meta information, e.g.: list of endpoints, Swagger documentation, and basic API metrics:\n\n```\n/\n/api/v1\n/api/v1/docs/\n/api/v1/metrics\n/api/v1/resource/\n/api/v1/resource/all\n/api/v1/resource/cpu\n/api/v1/resource/host\n/api/v1/resource/load\n/api/v1/resource/memory\n/api/v1/resource/network\n```\n\n\u003chr\u003e\n\n### Docker\n\n#### Build\n\nSimilarly to the above, you can run the application in a Docker container.\n\nConfigure your .env file, if desired:\n\n```\nSERVERPORT=5000\nDOCKERPORT=5000\nDEBUG=false\nDOCKERIMAGE=mattwiater/golangdocker\n```\n\nNote the **DOCKERIMAGE** name, your Docker image will be build with this variable.\n\nFirst, build via the Makefile: `make docker-build`\n\nOnce you have built your image successfully, check the output of the `docker images` command:\n\n```\nREPOSITORY                TAG       IMAGE ID       CREATED          SIZE\nmattwiater/golangdocker   latest    053f21052659   1 minute ago     26.4MB\n...\n```\n\nYou should see your new image in the list.\n\n#### Run\n\n`make docker-run`\n\nSame output as the App output above as you will be dropped into an interactive Docker shell...","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwiater%2Fgolangdocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwiater%2Fgolangdocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwiater%2Fgolangdocker/lists"}