Bootstrap FreeKB - GitHub Actions - Push an image to Docker Hub using docker/build-push-action
GitHub Actions - Push an image to Docker Hub using docker/build-push-action

Updated:   |  GitHub Actions articles

https://github.com/docker/build-push-action can be used to build and push an image to Docker Hub. For example, let's say you have the following workflow.

name: build and push image to Docker Hub
run-name: ${{ github.workflow }} run by ${{ github.actor }}
on:
  workflow_dispatch:
jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      -
        name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ vars.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      -
        name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      -
        name: Build and push
        uses: docker/build-push-action@v6
        with:
          push: true
          tags: johndoe/hello-world:0.0.0

 

By default, this workflow expects there to be a file named Dockerfile in the base directory of your GitHub repo. Let's say Dockerfile contains the following.

FROM alpine
CMD ["echo", "Hello World"]

 

In this example, the image will be pushed to the https://hub.docker.com/repositories/johndoe repo and tagged hello-world version 0.0.0. Assuming the workflow completes successfully, the image should be built and pushed to Docker Hub.

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 7b3e1e in the box below so that we can be sure you are a human.