You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Well I thought why not crafting a simple and small hello-world image and publish it to GitHub Container Registry?!
TLDR; Simply run it with:
docker run ghcr.io/jonashackt/hello-world
A simple Go executable
The original hello-world image from Docker also uses a small executable to print a text. I decided to go with golang to create a ultra-small executable myself.
funcmain() { fmt.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") }
Build it (you need to have go installed with like brew install go) with:
go build hello-world.go
This produces a hello-world executable you can simply run with ./hello world.
A Docker multistage Build for GO
As 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:
$ docker images golang latest 861b1afd1d13 7 days ago 862MB
The second "run" image is based on the same https://hub.docker.com/_/alpine image as the builder image containing the GO runtimes.
Now let's build and run our image:
$ docker build . --tag hello-world $ docker run hello-world Hello from Docker on GitHub Container Registry! This message shows that your installation appears to be working correctly.
As Docker Inc introduced rate-limiting in https://www.docker.com/increase-rate-limits we simply need our own hello-world image on GitHub Container Registry.
To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled this "hello-world" image from the GitHub Container Registry. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
The resulting image is around 7.55MB which should be small enough for our use cases.
Publish the Docker image to GitHub Container Registry
The 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:
To 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:
Now 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:
We should finally be able to pull and run our image! Just run:
docker pull ghcr.io/jonashackt/hello-world:latest
docker run ghcr.io/jonashackt/hello-world:latest
About
Example hello world container showing how to use GitHub Container Registry