{"id":13714389,"url":"https://github.com/miguno/golang-docker-build-tutorial","last_synced_at":"2025-05-07T01:33:40.191Z","repository":{"id":57539397,"uuid":"130427737","full_name":"miguno/golang-docker-build-tutorial","owner":"miguno","description":"A template project to create a minimal Docker image for a Go application","archived":false,"fork":false,"pushed_at":"2024-09-12T17:32:52.000Z","size":85,"stargazers_count":64,"open_issues_count":0,"forks_count":15,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-06T05:08:24.693Z","etag":null,"topics":["build","container","docker","example","go","golang","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Just","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/miguno.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":"2018-04-21T01:07:56.000Z","updated_at":"2025-05-05T01:47:15.000Z","dependencies_parsed_at":"2024-11-14T01:31:17.008Z","dependency_job_id":"b9fc4e9e-98d5-413c-8c9c-cc222af1972b","html_url":"https://github.com/miguno/golang-docker-build-tutorial","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miguno%2Fgolang-docker-build-tutorial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miguno%2Fgolang-docker-build-tutorial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miguno%2Fgolang-docker-build-tutorial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/miguno%2Fgolang-docker-build-tutorial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/miguno","download_url":"https://codeload.github.com/miguno/golang-docker-build-tutorial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252796099,"owners_count":21805498,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["build","container","docker","example","go","golang","tutorial"],"created_at":"2024-08-02T23:01:58.532Z","updated_at":"2025-05-07T01:33:39.930Z","avatar_url":"https://github.com/miguno.png","language":"Just","funding_links":[],"categories":["tutorial","Repositories"],"sub_categories":[],"readme":"# Project Template: Create a Docker image for a Go application\n\n[![GitHub forks](https://img.shields.io/github/forks/miguno/golang-docker-build-tutorial)](https://github.com/miguno/golang-docker-build-tutorial/fork)\n[![Docker workflow status](https://github.com/miguno/golang-docker-build-tutorial/actions/workflows/docker-image.yml/badge.svg)](https://github.com/miguno/golang-docker-build-tutorial/actions/workflows/docker-image.yml)\n[![Go workflow status](https://github.com/miguno/golang-docker-build-tutorial/actions/workflows/go.yml/badge.svg)](https://github.com/miguno/golang-docker-build-tutorial/actions/workflows/go.yml)\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nA template project to create a Docker image for a Go application.\nThe example application exposes an HTTP endpoint.\n\n\u003e [!TIP]\n\u003e\n\u003e **Java developer?** Check out https://github.com/miguno/java-docker-build-tutorial\n\nFeatures:\n\n- The Docker build uses a\n  [multi-stage build setup](https://docs.docker.com/build/building/multi-stage/)\n  to minimize the size of the generated Docker image, which is 5MB\n- Supports [Docker BuildKit](https://docs.docker.com/build/)\n- Golang 1.22\n- [GitHub Actions workflows](https://github.com/miguno/golang-docker-build-tutorial/actions) for\n  [Golang](https://github.com/miguno/golang-docker-build-tutorial/actions/workflows/go.yml)\n  and\n  [Docker](https://github.com/miguno/golang-docker-build-tutorial/actions/workflows/docker-image.yml)\n- Optionally, uses\n  [just](https://github.com/casey/just)\n  ![](https://img.shields.io/github/stars/casey/just)\n  for running common commands conveniently, see [justfile](justfile).\n- Uses [.env](.env) as central configuration to set variables used by\n  [justfile](justfile) and other helper scripts in this project.\n\n# Requirements\n\nDocker must be installed on your local machine. That's it. You do not need to\nhave Go installed.\n\n# Usage and Demo\n\n**Step 1:** Create the Docker image according to [Dockerfile](Dockerfile).\nThis step builds, tests, and packages the [Go application](app.go).\nThe resulting image is 5MB in size.\n\n```shell\n# ***Creating an image may take a few minutes!***\n$ docker build --build-arg PROJECT_VERSION=1.0.0-alpha -t miguno/golang-docker-build-tutorial:latest .\n\n# You can also build with the new BuildKit.\n# https://docs.docker.com/build/\n$ docker buildx build --build-arg PROJECT_VERSION=1.0.0-alpha -t miguno/golang-docker-build-tutorial:latest .\n```\n\nOptionally, you can check the size of the generated Docker image:\n\n```shell\n$ docker images miguno/golang-docker-build-tutorial\nREPOSITORY                            TAG       IMAGE ID       CREATED          SIZE\nmiguno/golang-docker-build-tutorial   latest    2de05b854c1b   11 minutes ago   4.78MB\n```\n\n**Step 2:** Start a container for the Docker image.\n\n```shell\n$ docker run -p 8123:8123 miguno/golang-docker-build-tutorial:latest\n```\n\n**Step 3:** Open another terminal and access the example API endpoint of the\nrunning container.\n\n```shell\n$ curl http://localhost:8123/status\n{\"status\": \"idle\"}\n```\n\n# Usage with just\n\nIf you have [just](https://github.com/casey/just) installed, you can run the\ncommands above more conveniently:\n\n```shell\n$ just\nAvailable recipes:\n    audit                   # detect known vulnerabilities (requires https://github.com/sonatype-nexus-community/nancy)\n    build                   # build executable for local OS\n    coverage                # show test coverage\n    default                 # print available targets\n    deps                    # show dependencies\n    docker-image-create     # create a docker image (requires Docker)\n    docker-image-run        # run the docker image (requires Docker)\n    docker-image-size       # size of the docker image (requires Docker)\n    evaluate                # evaluate and print all just variables\n    explain lint-identifier # explain lint identifier (e.g., \"SA1006\")\n    format                  # format source code\n    lint                    # run linters (requires https://github.com/dominikh/go-tools)\n    outdated                # detect outdated modules (requires https://github.com/psampaz/go-mod-outdated)\n    release                 # build release executables for all supported platforms\n    run                     # run executable for local OS\n    send-request-to-app     # send request to the app's HTTP endpoint (requires running container)\n    system-info             # print system information such as OS and architecture\n    test *FLAGS             # run tests with colorized output (requires https://github.com/kyoh86/richgo)\n    test-vanilla *FLAGS     # run tests (vanilla), used for CI workflow\n    tidy                    # add missing module requirements for imported packages, removes requirements that aren't used anymore\n    vulnerabilities         # detect known vulnerabilities (requires https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck)\n```\n\nExample:\n\n```shell\n$ just docker-image-create\n$ just docker-image-run\n```\n\n# Notes\n\nYou can run the Go application locally if you have Go installed.\nSee [justfile](justfile) for additional commands and options.\n\n```shell\n# Build\n$ go build -trimpath -ldflags=\"-w -s\" -v -o app cmd/golang-docker-build-tutorial/main.go\n\n# Test\n$ go test -cover -v ./...\n\n# Run\n$ ./app\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiguno%2Fgolang-docker-build-tutorial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmiguno%2Fgolang-docker-build-tutorial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmiguno%2Fgolang-docker-build-tutorial/lists"}