How can I update full description on Docker Hub automatically? How can I update full description on Docker Hub automatically? docker docker

How can I update full description on Docker Hub automatically?


Since the Docker Hub does not expose any API, the only way to send stuff to the Docker Hub remotely is with the docker push command, and this limits use to sending images.

On the other hand, if you let the Docker Hub service build your image for you from a Github or Bitbucket repository, then Docker Hub will update the long description by taking the content of the README.md file found on that repository. See the Understand the build process section from the Docker Hub's Automated Build documentation.

This implies that you host your Dockerfile and README.md files on Github or Bitbucket.


If you really need to first build your image on TravisCI (maybe because you also run automated tests on the built image), then you can have TravisCI trigger a webhook on Docker Hub to tell Docker Hub to build the image once TravisCI determined it was passing the tests.

To do so, in Docker Hub, configure your image as you would for automated build (hence associate a Github or Bitbucket project), but deactivate the automated feature:

Docker Hub project build settings

Then scroll down on the Build settings page to the Build Trigger section and copy the trigger URL:

Docker Hub project build trigger

Now edit your .travis.yml file and add the following block (mind the <your account> and <your image> placeholders):

after_success:# notify Docker Hub to make a new build- >  [ "$TRAVIS_BRANCH" == "master" ]  && curl -X POST -H "Content-Type: application/json"  --data '{"docker_tag_name": "latest"}'  https://registry.hub.docker.com/u/<your account>/<your image>/trigger/$DOCKER_HUB_TOKEN/

Then go to your project page on the Travis CI website, and open the project settings:

Travis CI project settings

And add the DOCKER_HUB_TOKEN environment variable to your Travis CI project with the trigger token value found on the Docker Hub Build Settings page:

Travis CI project environment variables

You will still need a Github or Bitbucket repository associated to your Docker Hub project, but Travis CI will be the one to instruct Docker Hub when to build your image.


Actually, you can update it using API

local code=$(jq -n --arg msg "$(<README.md)" \    '{"registry":"registry-1.docker.io","full_description": $msg }' | \        curl -s -o /dev/null  -L -w "%{http_code}" \           https://cloud.docker.com/v2/repositories/"${image}"/ \           -d @- -X PATCH \           -H "Content-Type: application/json" \           -H "Authorization: JWT ${token}")

See details here


I have a GitHub Action to do this.https://github.com/peter-evans/dockerhub-description

    - name: Docker Hub Description      uses: peter-evans/dockerhub-description@v2.1.0      env:        DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}        DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}        DOCKERHUB_REPOSITORY: peterevans/dockerhub-description

You can also use it independently of GitHub Actions in other CI tools.

    docker run -v $PWD:/workspace \      -e DOCKERHUB_USERNAME='user1' \      -e DOCKERHUB_PASSWORD='xxxxx' \      -e DOCKERHUB_REPOSITORY='my-docker-image' \      -e README_FILEPATH='/workspace/README.md' \      peterevans/dockerhub-description:2.1.0

Note: This does not work if you are using 2 Factor Authentication (2FA) and/or using Personal Access Tokens to authenticate to Docker Hub. You must use your actual Docker Hub password. See issue reported here: https://github.com/docker/hub-feedback/issues/1927