This guide helps you automate html pages deployment to Docker Hub.
Create an empty repository on GitHub named docker-github-action (or any name of your choice).
Clone the repository to your local machine using the following command:
git clone https://github.com/shivasharma/IS436-Classwork-Foosball.git
Create an account on Dockerhub
Click on your profile =>Account Settings=> Click Personal Access Token => Generate Token => Save the token on your computer.
Log in to Github= >Select your repositroy => Click on Action => New workflow/Search Simple Workflow => Configure => Commit change
Your repositroy should have .github/workflow/somefile.yml added to your repository
.github/workflows/docker.yml
Paste the following YAML configuration:
Create .github/workflows/docker.yml folder structure directly inside the repositroy using vscode
.github/workflows/docker.yml
Paste the following YAML configuration:
name: Build and Push to Docker Hub
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Build Docker Image
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/is147:${{ github.run_number }} .
- name: Push Docker Image
run: docker push ${{ secrets.DOCKER_USERNAME }}/is147:${{ github.run_number }}
Now commit and push your changes to trigger the GitHub Action:
git add .
git commit -m "Automate Docker build and push"
git push origin main
OR
From vscode git=> commit =>commit and push
Once the workflow completes, you can pull and run the image from Dockerhub:
docker pull your-dockerhub-username/hello-world:tagname
eg docker pull shivathebravo/foosball:28
docker images
docker run -d -p 80:80 --name yourppname your-dockerhub-username/appname:tagname
docker run -d -p 80:80 --name foosball shivathebravo/foosball:28