CI/CD with GitHub Actions: Build & Push Docker Images to Docker Hub

Published: 29 January 2025
on channel: Spyros Katsios
118
9

Hi there! Today we are going to see how to build and push a Docker image to Docker Hub, as part of your CI/CD pipeline, using GitHub Workflows.

yaml file:

name: Build and push to Dockerhub

on:
push:
branches:
main

jobs:
push:
runs-on: ubuntu-latest

steps:
name: Checkout
uses: actions/checkout@v4

name: Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

name: Build and push Docker image
uses: docker/[email protected]
with:
context: .
file: ./Weather.Api/Dockerfile
push: true
tags: |
repo-name:${{ github.sha }}
repo-name/weather-api:latest

#GitHubActions #Docker