Deploying Microservices with Docker

Once microservices are built and tested, the next step is deploying them. Docker simplifies deployment to any environment that supports containers — from local servers to major cloud platforms.


Pushing Microservices to Docker Hub

Docker Hub is a cloud-based registry for sharing container images.

  1. Tag your image:
    docker tag user-service username/user-service:latest
  2. Log in to Docker Hub:
    docker login
  3. Push the image:
    docker push username/user-service:latest

Deploying to a Cloud Provider

Most cloud providers support Docker images natively. For example, deploying to AWS ECS or Azure Container Apps:

  • AWS: Push to Amazon ECR and deploy with ECS or Fargate
  • Azure: Push to Azure Container Registry (ACR) and deploy using Azure App Services or Azure Kubernetes Service

Example for running a container on Azure:

az webapp create --name user-api --resource-group myRG --plan myPlan \
--deployment-container-image-name username/user-service:latest

Automating Deployments with CI/CD

Integrate Docker into CI/CD pipelines using GitHub Actions, GitLab CI, Jenkins, or Azure DevOps:

# GitHub Actions: .github/workflows/docker-deploy.yml
name: Build & Deploy

on:
  push:
    branches: [ main ]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Build Docker image
        run: docker build -t username/user-service .
      - name: Push to Docker Hub
        run: |
          echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
          docker push username/user-service

This pipeline builds and pushes your Docker image every time you push to main.

Deployment with Docker is streamlined and portable across cloud providers. Combine Docker with CI/CD to automate and accelerate your release pipeline.