Publishing Docker Images

Using GitHub Actions to publish Docker images

Docker images for CHT projects can be published to the medicmobile Docker Hub organization, so they are easily accessible to the community. This process can be automated using GitHub actions.

Create repository on Docker Hub

First, create a repository for your new image on Docker Hub.

  1. Use the admin Docker account to create a new repository in the medicmobile organization.
  2. For your new repository, update the permissions to give the developers team the ability to Read & Write. This will allow the GitHub action to push to the repository.

Add GitHub Action Workflow configuration

Now that the Docker Hub repository is created, you can add the GitHub Action workflow configuration to your project. This configuration should build the Docker image based on the code in the repository and then publish it to the Docker Hub repository.

Here is an example of a basic workflow configuration that publishes a new image for each tag that is pushed:

name: Publish Docker image

    tags: ['v*']

  DOCKER_HUB_USER: dockermedic
  DOCKER_NAMESPACE: medicmobile

    name: Push Docker image to Docker Hub
    runs-on: ubuntu-22.04
      - name: Check out the repo
        uses: actions/checkout@v3

      - name: Log in to Docker Hub
        uses: docker/login-action@v2
          username: ${{ env.DOCKER_HUB_USER }}
          password: ${{ secrets.DOCKER_HUB_PASS }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v4
          images: ${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_REPOSITORY }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v4
          context: .
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

Do not forget to update the DOCKER_REPOSITORY environment variable with the name of the repository you created on Docker Hub. Also note that the DOCKER_HUB_PASS secret is an org level secret. So, no special configuration should be required to use this secret for any repositories in the medic organization.

This configuration will create and publish a new Docker image for each tag that is pushed to the repository. The image will be tagged with the tag name and the latest tag.

CHT Core Framework > Releases

Versions currently supported, dependencies, and release notes for the CHT Core Framework