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

I use Travis CI to create docker images with Dockerfiles, and then successfully promote them to the Docker Hub.

I created an MD file that describes the image and how to use it. I want to have the same description on the Docker Hub in the full description section.

How can I update the description in the future, I want Travis CI to automatically update the description based on the MD file in the repository with a new image.

Does anyone know how to do this?

+10
source share
4 answers

Since the Docker Hub does not provide any API , the only way to send stuff to the Docker Hub remotely is with the docker push , and this restriction is used to send images.

On the other hand, if you let the Docker Hub service create your image for you from the Github or Bitbucket repository, the Docker Hub will update the long description by taking the contents of the README.md file found in this repository. See Understanding the Build Process from the Docker Hub Automated Build documentation.

This means that you host the Dockerfile and README.md files on Github or Bitbucket.


If you really need to first create your image on TravisCI (perhaps because you also run automatic tests on the embedded image), you can force TravisCI to run a web host on the Docker Hub to tell the Docker Hub to create the image after determining TravisCI it passed tests.

To do this, configure the image in the Docker Hub in the same way as for automatic assembly (therefore, link the Github or Bitbucket project), but disable the automatic function:

Docker Hub project build options

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

Docker hub project build trigger

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

 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 the project page on the Travis CI website and open the project settings:

Travis CI Project Settings

And add the DOCKER_HUB_TOKEN environment DOCKER_HUB_TOKEN to the 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 the Github or Bitbucket repository associated with your Docker Hub project, but Travis CI will instruct the Docker Hub when creating your image.

+9
source

In fact, you can update it using the 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}") 

Details here

+4
source

I have a github action for 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 
+2
source

you can use docker container in your pipeline using this

https://hub.docker.com/r/sheogorath/readme-to-dockerhub

Project code

https://github.com/SISheogorath/readme-to-dockerhub

The configuration of the Gitlab CI Pipeline is as follows

 update-readme: stage: docs image: name: docker:stable services: - docker:dind script: - docker run --rm -v $(pwd)/README.md:/data/README.md -e DOCKERHUB_USERNAME=$CI_REGISTRY_USER -e DOCKERHUB_PASSWORD=$CI_REGISTRY_PASSWORD -e DOCKERHUB_REPO_PREFIX=$CI_REGISTRY_IMAGE -e DOCKERHUB_REPO_NAME=$CONTAINER_NAME sheogorath/readme-to-dockerhub 

I also have a smaller command that you can also use if you run it in the Docker repository, it will read README.md by default

  docker run --rm -v $(pwd):/data/ aemdesign/dockerhub-description "$DOCKER_USERNAME" "$DOCKER_PASSWORD" aemdesign/dispatcher 

If you want to specify manually, run

  docker run --rm -v $(pwd):/data/ aemdesign/dockerhub-description "$DOCKER_USERNAME" "$DOCKER_PASSWORD" aemdesign/dispatcher ./README.md 

code: https://github.com/aem-design/docker-dockerhub-description

0
source

Source: https://habr.com/ru/post/1240285/


All Articles