How do I use Docker with GitHub Actions?
Last Updated :
23 Jul, 2025
Docker packages all the components required for software into containers, much like a recipe box. By automating chores in your development workflow, GitHub Actions serves as your personal chef. When combined, they optimize software development by effectively packaging applications and smoothly automating monotonous operations. While GitHub Actions automates tasks like testing and deployment, Docker guarantees consistency in application deployment. Docker integration with GitHub Actions produces an effective workflow for easily developing, testing, and deploying apps. This combination makes it easier for teams to produce high-quality software quickly and improves communication across the software development lifecycle.
Step-by-step instructions for using Docker with GitHub Actions
Step 1: Create the repository.
Step 2: Here is my repository maven web app.

Here is the code i used and kept in the workflow file.
name: Java CI with Maven, Docker, and Cloud Run
on:
workflow_dispatch:
# push:
# branches: [ master ]
# pull_request:
# branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Archive Artifact
uses: actions/upload-artifact@v2
with:
name: maven-web-application
path: /home/runner/work/maven-web-application/maven-web-application/target/maven-web-application.war
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image to DockerHub
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: larasai/maven-web-app:v1
- name: install the gcloud cli
uses: google-github-actions/setup-gcloud@v0
with:
project_id: ${{ secrets.GCLOUD_PROJECT_ID }}
service_account_key: ${{ secrets.GCLOUD_SA_KEY }}
export_default_credentials: true
- name: Build and push Docker image to Google Artifact Registry
run: |
gcloud auth configure-docker us-central1-docker.pkg.dev
docker pull larasai/maven-web-app:v1
docker tag larasai/maven-web-app:v1 us-central1-docker.pkg.dev/stone-trees-422304-p7/demo-app/maven-web-app:v1
docker push us-central1-docker.pkg.dev/stone-trees-422304-p7/demo-app/maven-web-app:v1
- name: Deploy to Cloud Run
uses: google-github-actions/deploy-cloudrun@v2
with:
service: maven-web-app
image: us-central1-docker.pkg.dev/stone-trees-422304-p7/demo-app/maven-web-app:v1
platform: managed
region: us-central1
project_id: ${{ secrets.GCLOUD_PROJECT_ID }}
service_account_key: ${{ secrets.GCLOUD_SA_KEY }}
flags: '--allow-unauthenticated'
Here is the detail explanation about the code.
- on:
- This section defines when the workflow should run. In this case, it's configured to run manually (
workflow_dispatch
), meaning someone needs to trigger it explicitly. The commented-out lines indicate configurations for running the workflow automatically on specific events like pushes to the master branch or pull requests.
- jobs:
- This workflow contains one job named "build", which defines a series of steps to execute.
- runs-on:
- Specifies the type of virtual machine to run the job on. In this case, it's set to
ubuntu-latest
.
- steps:
- This section contains the individual tasks to be executed as part of the job.
- actions/checkout@v2:
- Checks out the code repository into the runner's workspace.
- actions/setup-java@v4:
- Sets up Java 11 for the job using AdoptOpenJDK, and configures Maven caching for faster builds.
- Build with Maven:
- Runs the Maven command to build the Java web application using the specified
pom.xml
file.
- Archive Artifact:
- Uploads the built artifact (in this case, a
.war
file) to GitHub as an artifact, making it available for download in subsequent steps or workflows.
- docker/setup-buildx-action@v1:
- Sets up Docker Buildx, a Docker CLI plugin for extended build capabilities.
- docker/login-action@v2:
- Logs in to DockerHub using provided credentials stored in GitHub secrets.
- docker/build-push-action@v2:
- Builds the Docker image using the specified Dockerfile, tags it with a version (
larasai/maven-web-app:v1
), and pushes it to DockerHub.
- google-github-actions/setup-gcloud@v0:
- Sets up the Google Cloud SDK (gcloud) CLI for interacting with Google Cloud services.
- Build and push Docker image to Google Artifact Registry:
- Configures Docker to authenticate with Google Artifact Registry, pulls the Docker image from DockerHub, retags it, and pushes it to Google Artifact Registry.
- Deploy to Cloud Run:
- Deploys the Docker image to Google Cloud Run, a managed serverless platform, using the specified image from Google Artifact Registry. It configures the deployment to be accessible without authentication, using the provided Google Cloud Project ID and service account key.
Step 3: CLick on actions and click on the java ci with maven on left sisde and trigger the pipeline.

Step 4: The process was successfully executed here is the build.

Step 5: Refer the below image and the all steps was completed successfully.

Step 6: Here the image was successfully build and pushed to the docker hub refer the below image.

Step 7: We have stored the all secrets in the repository secrets.

Step 8: The docker build image was successfully pushed in to the google cloud artifact repository refer the below image. In service account we need to provide the sufficient permissions while pushing the image inro the artifact repository.

Step 9: The application was successfully deployed into the cloudrun service for your reference refer the below image.

Step 10: The revision was successfully created, here are the revision details and that is serving the traffic successfully.

Step 11: Here is the application tomcat web page.

Conclusion
Docker and GitHub Actions work together to streamline software development, testing, and deployment. Applications are cleanly packaged by Docker, guaranteeing consistent operation everywhere. Development is streamlined by GitHub Actions, which automates processes like testing and deployment. Teams may quickly set up and start the workflow by following the included step-by-step instructions. Software delivery is accelerated and cooperation is improved by this integration. Teams may confidently and effectively produce high-quality software by utilizing Docker and GitHub Actions.
Similar Reads
DevOps Tutorial DevOps is a combination of two words: "Development" and "Operations." Itâs a modern approach where software developers and software operations teams work together throughout the entire software life cycle.The goals of DevOps are:Faster and continuous software releases.Reduces manual errors through a
7 min read
Introduction
What is DevOps ?DevOps is a modern way of working in software development in which the development team (who writes the code and builds the software) and the operations team (which sets up, runs, and manages the software) work together as a single team.Before DevOps, the development and operations teams worked sepa
10 min read
DevOps LifecycleThe DevOps lifecycle is a structured approach that integrates development (Dev) and operations (Ops) teams to streamline software delivery. It focuses on collaboration, automation, and continuous feedback across key phases planning, coding, building, testing, releasing, deploying, operating, and mon
10 min read
The Evolution of DevOps - 3 Major Trends for FutureDevOps is a software engineering culture and practice that aims to unify software development and operations. It is an approach to software development that emphasizes collaboration, communication, and integration between software developers and IT operations. DevOps has come a long way since its in
7 min read
Version Control
Continuous Integration (CI) & Continuous Deployment (CD)
Containerization
Orchestration
Infrastructure as Code (IaC)
Monitoring and Logging
Microsoft Teams vs Slack Both Microsoft Teams and Slack are the communication channels used by organizations to communicate with their employees. Microsoft Teams was developed in 2017 whereas Slack was created in 2013. Microsoft Teams is mainly used in large organizations and is integrated with Office 365 enhancing the feat
4 min read
Security in DevOps