docker meets github image registry: the game‑changing workflow every dev must master

why combine docker with github image registry?

in today’s devops landscape, containers have become the de facto standard for packaging and deploying applications. pairing docker with the github image registry (also known as ghcr) gives you a seamless, full‑stack workflow that is easy to learn, version, and share. even beginners can master it in just a few steps, and it boosts the seo of your project by keeping your documentation and code in one place.

prerequisites

  • github account with write permissions on a repository.
  • docker engine installed (docker desktop works on windows/macos, docker engine on linux).
  • basic familiarity with the command line and git.

step‑by‑step workflow

1. create a new repository (or use an existing one)

start by creating a repository on github where you will store both your source code and the docker image metadata.

git init my‑awesome‑app
cd my‑awesome‑app
git remote add origin https://github.com/username/my‑awesome‑app.git

2. write a simple dockerfile

let’s build a tiny node.js “hello world” app. this example is deliberately simple so you can focus on the workflow, not the app itself.

# dockerfile
from node:20-alpine
workdir /app
copy package*.json ./
run npm install
copy . .
expose 3000
cmd ["node", "index.js"]

3. test the image locally

before pushing anything to github, make sure the image builds and runs correctly on your machine.

# build the image
docker build -t my‑awesome‑app:dev .

# run the container
docker run -p 3000:3000 my‑awesome‑app:dev

open http://localhost:3000 in your browser—you should see the “hello world” message.

4. authenticate with ghcr

github uses a personal access token (pat) to authenticate docker pushes. create a new token with the write:packages scope.

# log in to ghcr (replace your_token with the pat)
echo your_token | docker login ghcr.io -u username --password-stdin

5. tag and push the image

use the fully qualified name ghcr.io/<owner>/<repo>:<tag>. tagging follows the semantic versioning convention to keep things clear for teammates.

# tag the image
docker tag my‑awesome‑app:dev ghcr.io/username/my‑awesome‑app:v1.0.0

# push to ghcr
docker push ghcr.io/username/my‑awesome‑app:v1.0.0

6. verify the image on github

navigate to packages in your repository settings. you should see my‑awesome‑app listed with the version you just pushed.

automating the process with github actions

manual pushes are fine for learning, but production‑grade projects benefit from automation. below is a straightforward workflow that builds, tests, and pushes the docker image whenever code lands on the main branch.

# .github/workflows/docker-publish.yml
name: build & publish docker image

on:
  push:
    branches: [ main ]

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
      - name: checkout repository
        uses: actions/checkout@v3

      - name: set up docker buildx
        uses: docker/setup-buildx-action@v2

      - name: log in to ghcr
        uses: docker/login-action@v2
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.github_token }}

      - name: build and push docker image
        uses: docker/build-push-action@v4
        with:
          context: .
          push: true
          tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:v${{ github.run_number }}

save this file, commit, and push. github will automatically execute the job, giving you a reliable ci/cd pipeline.

best practices for beginners

  • keep dockerfiles small: use multi‑stage builds to reduce image size.
  • version your images: semantic version tags (e.g., v1.2.3) make rollbacks easy.
  • store secrets securely: never hard‑code passwords; use github secrets for tokens.
  • document the workflow: add a readme.md section that explains how to run the container locally and how the ci pipeline works.

putting it all together – a sample project structure

.
├── .github
│   └── workflows
│       └── docker-publish.yml
├── dockerfile
├── index.js
├── package.json
└── readme.md

conclusion

mastering the docker + github image registry workflow is a game‑changing skill for any developer, whether you’re a student learning devops fundamentals or an engineer building production‑grade services. by following the steps above, you’ll have a reproducible, version‑controlled pipeline that streamlines development, testing, and deployment—all while keeping your project seo‑friendly and easier for teammates to discover.

start experimenting today, and soon you’ll wonder how you ever managed projects without this powerful integration!

Comments

Discussion

Share your thoughts and join the conversation

Loading comments...

Join the Discussion

Please log in to share your thoughts and engage with the community.