{"id":16179231,"url":"https://github.com/jonashackt/docker-hello-world","last_synced_at":"2025-03-16T10:31:38.889Z","repository":{"id":40307628,"uuid":"341836507","full_name":"jonashackt/docker-hello-world","owner":"jonashackt","description":"Example hello world container showing how to use GitHub Container Registry","archived":false,"fork":false,"pushed_at":"2024-12-06T03:44:33.000Z","size":2191,"stargazers_count":14,"open_issues_count":7,"forks_count":26,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-27T07:42:58.769Z","etag":null,"topics":["alpine","docker","github-actions","github-container-registry","go","hello-world"],"latest_commit_sha":null,"homepage":"","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/jonashackt.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":"2021-02-24T08:51:53.000Z","updated_at":"2024-12-06T03:44:36.000Z","dependencies_parsed_at":"2024-10-10T05:33:28.758Z","dependency_job_id":"805b504e-9487-4acf-92e2-3ced8db9bb65","html_url":"https://github.com/jonashackt/docker-hello-world","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fdocker-hello-world","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fdocker-hello-world/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fdocker-hello-world/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonashackt%2Fdocker-hello-world/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonashackt","download_url":"https://codeload.github.com/jonashackt/docker-hello-world/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814895,"owners_count":20352036,"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":["alpine","docker","github-actions","github-container-registry","go","hello-world"],"created_at":"2024-10-10T05:26:09.640Z","updated_at":"2025-03-16T10:31:38.553Z","avatar_url":"https://github.com/jonashackt.png","language":"Go","readme":"# docker-hello-world\n[![Build Status](https://github.com/jonashackt/docker-hello-world/workflows/publish/badge.svg)](https://github.com/jonashackt/docker-hello-world/actions)\n[![renovateenabled](https://img.shields.io/badge/renovate-enabled-yellow)](https://renovatebot.com)\n\nExample hello world container showing how to use GitHub Container Registry\n\n\nAs Docker Inc introduced a rate-limiting https://www.docker.com/increase-rate-limits I began to bump [into problems like this](https://github.com/jonashackt/molecule-ansible-docker-aws/runs/1968417806?check_suite_focus=true) while running a simple `docker run hello-world` on GitHub Actions:\n\n```\nUnable to find image 'hello...se the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit.\\nSee 'docker run --help'.\\n\"\n```\n\nMany [people started to migrate their Docker images](https://medium.com/faun/migrating-my-docker-images-to-the-github-container-registry-9f304ccf0aaa) to the new GitHub Container Registry, which is currently in public beta: https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images\n\nAnd there are already many projects that are simply not available anymore on DockerHub - but on GitHub Container Registry (like https://hub.docker.com/r/oracle/graalvm-ce to https://github.com/orgs/graalvm/packages/container/package/graalvm-ce)\n\nWell I thought why not crafting a simple and small `hello-world` image and publish it to GitHub Container Registry?!\n\n__TLDR;__ Simply run it with:\n\n```shell\ndocker run ghcr.io/jonashackt/hello-world\n```\n\n### A simple Go executable\n\nThe [original hello-world image from Docker](https://github.com/docker-library/hello-world) also uses a small executable to print a text. I decided to go with golang to create a ultra-small executable myself. \n\nSo there's [hello-world.go](hello-world.go):\n\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello from Docker on GitHub Container Registry!\\nThis message shows that your installation appears to be working correctly.\\n\\nAs Docker Inc introduced rate-limiting in https://www.docker.com/increase-rate-limits\\nwe simply need our own hello-world image on GitHub Container Registry.\\n\\nTo generate this message, Docker took the following steps:\\n 1. The Docker client contacted the Docker daemon.\\n 2. The Docker daemon pulled this \\\"hello-world\\\" image from the GitHub Container Registry.\\n    (amd64)\\n 3. The Docker daemon created a new container from that image which runs the\\n    executable that produces the output you are currently reading.\\n 4. The Docker daemon streamed that output to the Docker client, which sent it\\n    to your terminal.\\n\\n\")\n}\n```\n\nBuild it (you need to have go installed with like `brew install go`) with:\n\n```shell\ngo build hello-world.go\n```\n\nThis produces a `hello-world` executable you can simply run with `./hello world`.\n\n\n### A Docker multistage Build for GO\n\nAs we only need to have Go runtime stuff present to build the binary, we should implement a Docker multi-stage build. Since the GO Docker image https://hub.docker.com/_/golang is quite huge:\n```shell\n$ docker images\ngolang                             latest                861b1afd1d13   7 days ago       862MB\n```\n\nTherefore let's split our [Dockerfile](Dockerfile) a bit:\n\n```dockerfile\n# We need a golang build environment first\nFROM golang:1.16.0-alpine3.13\n\nWORKDIR /go/src/app\nADD hello-world.go /go/src/app\n\nRUN go build hello-world.go\n\n# We use a Docker multi-stage build here in order that we only take the compiled go executable\nFROM alpine:3.13\n\nCOPY --from=0 \"/go/src/app/hello-world\" hello-world\n\nENTRYPOINT ./hello-world\n```\n\nThe second \"run\" image is based on the same https://hub.docker.com/_/alpine image as the builder image containing the GO runtimes.\n\nNow let's build and run our image:\n\n```shell\n$ docker build . --tag hello-world\n$ docker run hello-world\nHello from Docker on GitHub Container Registry!\nThis message shows that your installation appears to be working correctly.\n\nAs Docker Inc introduced rate-limiting in https://www.docker.com/increase-rate-limits\nwe simply need our own hello-world image on GitHub Container Registry.\n\nTo generate this message, Docker took the following steps:\n 1. The Docker client contacted the Docker daemon.\n 2. The Docker daemon pulled this \"hello-world\" image from the GitHub Container Registry.\n    (amd64)\n 3. The Docker daemon created a new container from that image which runs the\n    executable that produces the output you are currently reading.\n 4. The Docker daemon streamed that output to the Docker client, which sent it\n    to your terminal.\n```\n\nThe resulting image is around `7.55MB` which should be small enough for our use cases.\n\n\n### Publish the Docker image to GitHub Container Registry\n\nWe follow the full guide here: https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images\n\n#### Activate improved container support\n\nFirst we need to activate the Container Registry beta feature in our account: https://docs.github.com/en/packages/guides/enabling-improved-container-support\n\n![github-improved-container-support](screenshots/github-improved-container-support.png)\n\n\n#### Authenticate and login to GitHub Container Registry using GITHUB_TOKEN\n\nFrom March 2021 on we should be able to use our `GITHUB_TOKEN` to authenticate against the GitHub Container Registry instead of using a separate PAT (see https://github.blog/changelog/2021-03-24-packages-container-registry-now-supports-github_token/)!\n\nSo our GHA workflow file [publish.yml](.github/workflows/publish.yml) should look like this:\n\n```yaml\nname: publish\n\non: [push]\n\njobs:\n  publish-hello-world-image:\n    runs-on: ubuntu-latest\n\n    steps:\n    - uses: actions/checkout@v2\n\n    - name: Build the hello-world Docker image\n      run: |\n        echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin\n\n```\n\nor Alternatively we can also use the [docker/login-action](https://github.com/docker/login-action) to to the login:\n\n```yaml\n    - name: Login to GitHub Container Registry\n      uses: docker/login-action@v1\n      with:\n        registry: ghcr.io\n        username: ${{ github.actor }}\n        password: ${{ secrets.GITHUB_TOKEN }}\n```\n\n\n#### Publish (Push) Container image to GHCR\n\nThe final step now is to push our container image to the GitHub Container Registry. Therefore we need to tag our image correctly while building it using `ghcr.io/OWNER/IMAGE_NAME:latest`. After that we can push it:\n\n```yaml\n        docker build . --tag ghcr.io/jonashackt/hello-world:latest\n        docker run ghcr.io/jonashackt/hello-world:latest\n        docker push ghcr.io/jonashackt/hello-world:latest\n```\n\nTo link our image to our GitHub repository (this isn't done automatically since images are treated as GH account global packages), we add a `LABEL` into our [Dockerfile](Dockerfile):\n\n```dockerfile\nLABEL org.opencontainers.image.source=\"https://github.com/jonashackt/docker-hello-world\"\n```\n\nWith this label the image package gets automatically linked to our repository:\n\n![image-package-linked-to-repository-by-label](screenshots/image-package-linked-to-repository-by-label.png)\n\nAnd also the image becomes visible on our repositories main page:\n\n![repo-main-page-package-shown](screenshots/repo-main-page-package-shown.png)\n\n\n#### Make your image publicly accessible\n\nPer default our container image is private on GitHub Container Registry: https://docs.github.com/en/packages/guides/configuring-access-control-and-visibility-for-container-images\n\nTo make it publicly accessible we need to move to our user account or orga page. For my account this is https://github.com/jonashackt?tab=packages\n\n![user-account-packages](screenshots/user-account-packages.png)\n\nNow click on the image published (which looks the same as a normal GH package) and then go to `Package Settings`. Now in the `Danger Zone` click on `change visibility` and choose `public`:\n\n![package-settings-visibility-public](screenshots/package-settings-visibility-public.png)\n\nWe should finally be able to pull and run our image! Just run:\n\n```shell\ndocker pull ghcr.io/jonashackt/hello-world:latest\n\ndocker run ghcr.io/jonashackt/hello-world:latest\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fdocker-hello-world","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonashackt%2Fdocker-hello-world","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonashackt%2Fdocker-hello-world/lists"}