• Shopping Cart Shopping Cart
    0Shopping Cart
London App Developer
  • Courses
  • Consulting
  • Tutorials
  • About
  • Click to open the search input field Click to open the search input field Search
  • Menu Menu
Docker and Travis CI logos with a caution sign
Docker, Travis-CI

Fixing toomanyrequests error when using Docker with Travis-CI

Students of our course Build a Backend REST API with Python & Django – Advanced have recently been getting the following issue when pulling Docker images in Travis-CI jobs:

ERROR: toomanyrequests: You have reached your pull rate limit. You may increase the limit by authenticating and upgrading: https://www.docker.com/increase-rate-limit
The command "docker-compose run --rm app sh -c "python manage.py wait_for_db && python manage.py test && flake8"" exited with 1.
Screenshot of toomanyrequests error.
Error showing toomanyrequests rate limit from Docker.

The problem occurs because Docker is now rate limiting image pulls.

There is a limit of 100 pulls for anonymous users, which are tracked via their IP address. Since services like Travis-CI may serve thousands of customers from the same IP, the free allocation is quickly consumed.

How to fix it?

Fortunately, Docker provide a generous 200 pulls every 6 hours to those with a registered account, which should be more than enough for your average project.

However, in order to use Docker on a shared CI/CD service (like Travis-CI), you need to make a few changes to authenticate.

In this guide, I’ll show you how to do that!

Create an account on Docker Hub

First, create a new free account at hub.docker.com.

Once logged in, click on your username (top right) and Account Settings:

Screenshot of the Account Settings option in Docker Hub.
Account settings option in Docker Hub

From the Account Settings page, choose Security and then click New Access Token.

New Access Token option

On the New Access Token screen, enter a name for your token (I suggest using the name of your GitHub project), and click Create.

On the Copy Access Token screen, take note of the access token and store it somewhere securely (we’ll need this further down), and click Copy and Close.

Note: There is no way to retrieve the token once this screen is closed. If you lose it, simply delete the token and create a new one.

Remember your username and token, because you’re going to need that next!

Add credentials to Travis-CI

Login to travis-ci.com.

Then select your project, and choose More options > Settings.

Screenshot of settings option for repository on Travis-CI.
Settings option for repository on Travis-CI

Locate the Environment Variables section, then add two new variables:

  • DOCKERHUB_USER – The username for your Docker Hub account.
  • DOCKERHUB_TOKEN – The token for your Docker Hub account.

Ensure you leave DISPLAY VALUE IN BUILD LOG unchecked for both values.

When done, it should look something like this:

Screenshot of Environment Variables section in Travis-CI.
Environment Variables section in Travis-CI

Modify Travis-CI Config

In your project, open the .travis-ci.yml file, and add the following block:

before_install:
  - echo $DOCKERHUB_TOKEN | docker login --username $DOCKERHUB_USER --password-stdin

This will do the following:

  • echo $DOCKER_PASSWORD prints the password to the screen, and the | (pipe) will send that output to the proceeding command.
  • docker login --username $DOCKER_USERNAME will call the docker login command with the username we set in the environment variables.
  • --password-stdin is used to accept the password in a way that prevents it being printed to the screen (it’s required with the | syntax).

If you’re following our course, the full .travis-ci.yml file would look something like this:

language: python
python:
  - "3.6"

services:
  - docker

before_install:
  - echo $DOCKERHUB_TOKEN | docker login --username $DOCKERHUB_USER --password-stdin

before_script: pip install docker-compose

script:
  - docker-compose run --rm app sh -c "python manage.py wait_for_db && python manage.py test && flake8"

Now your Docker build should work as expected.

Other Notes

Some people (like myself) may be uncomfortable with putting their Docker Hub credentials directly inside a project configuration, as this is not best practice from a security perspective, especially if you’re working on a shared project.

My current solution is to have a specific Docker Hub account that is only used for CI purposes.

If you need to push images, you can give this CI account permissions to push to the registry on your main account.

If anyone has any better approaches, I would love to hear about them in the comments or on Reddit!

Tags: auth, Docker, travis, travis-ci
Share this entry
  • Share on Facebook
  • Share on X
  • Share on WhatsApp
  • Share on Pinterest
  • Share on LinkedIn
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://i0.wp.com/londonappdeveloper.com/wp-content/uploads/2021/05/Docker-travis-ci-blog-post-1.png?fit=606%2C474&ssl=1 474 606 mark https://londonappdeveloper.com/wp-content/uploads/2018/12/lon_website_logo-300x110.png mark2021-05-28 18:39:402021-05-29 17:14:03Fixing toomanyrequests error when using Docker with Travis-CI
You might also like
Docker compose and Docker logos on a thumbnail Docker vs Docker Compose, what’s the difference?
Django and Docker compose logos on a blueish green background Deploying Django with Docker Compose
Setting up PostgreSQL database with a Django Docker application
Django Docker Deployment with HTTPS using Letsencrypt
Docker and VSCode logos on an orange background Use Docker to create a new Django project in one line
Add Backend to React with Django REST Framework and Docker
Debugging a Dockerized Django app with VSCode
Dockerizing a Django REST Framework Project
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Pages

  • About
  • Consulting
  • Home
  • Tutorials

Categories

  • AI
  • Android
  • Android Studio
  • Angular
  • Aptana Studio
  • AWS
  • Bootstrap
  • Career advice
  • Celery
  • Databases
  • Deployment
  • DevOps
  • Django
  • Django REST Framework
  • Docker
  • Eclipse
  • Getting Help
  • Git
  • Git Bash
  • Git Flow
  • GitHub Actions
  • Google App Engine
  • IDE
  • Ionic Framework
  • iOS
  • JavaScript
  • Job Search
  • Links
  • Linux
  • Mac OS X
  • macOS
  • Node.JS
  • OpenAI
  • PGAdmin
  • Postgres
  • Productivity
  • Python
  • React
  • Salt Stack
  • Stack Overflow
  • Tools
  • Travis-CI
  • Tutorials
  • Ubuntu
  • Uncategorized
  • Vagrant
  • VSCode
  • WebSockets
  • Windows 10
  • WordPress

London App Developer Ltd,

71-75 Shelton Street, Covent Garden, London, United Kingdom, WC2H 9JQ

Company registration number: 09718346

© London App Developer - London App Developer Ltd, Company Registration Number: 09718346, VAT: GB224061842
  • Link to X
  • Link to Youtube
  • Link to Facebook
  • Link to Reddit
Link to: Deploying Django to Google App Engine using Docker Link to: Deploying Django to Google App Engine using Docker Deploying Django to Google App Engine using DockerGoogle Cloud Platform, Docker and Django. Link to: Deploying Django with Docker Compose Link to: Deploying Django with Docker Compose Django and Docker compose logos on a blueish green backgroundDeploying Django with Docker Compose
Scroll to top Scroll to top Scroll to top

This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.

OKLearn more

Cookie and Privacy Settings



How we use cookies

We may request cookies to be set on your device. We use cookies to let us know when you visit our websites, how you interact with us, to enrich your user experience, and to customize your relationship with our website.

Click on the different category headings to find out more. You can also change some of your preferences. Note that blocking some types of cookies may impact your experience on our websites and the services we are able to offer.

Essential Website Cookies

These cookies are strictly necessary to provide you with services available through our website and to use some of its features.

Because these cookies are strictly necessary to deliver the website, refusing them will have impact how our site functions. You always can block or delete cookies by changing your browser settings and force blocking all cookies on this website. But this will always prompt you to accept/refuse cookies when revisiting our site.

We fully respect if you want to refuse cookies but to avoid asking you again and again kindly allow us to store a cookie for that. You are free to opt out any time or opt in for other cookies to get a better experience. If you refuse cookies we will remove all set cookies in our domain.

We provide you with a list of stored cookies on your computer in our domain so you can check what we stored. Due to security reasons we are not able to show or modify cookies from other domains. You can check these in your browser security settings.

Google Analytics Cookies

These cookies collect information that is used either in aggregate form to help us understand how our website is being used or how effective our marketing campaigns are, or to help us customize our website and application for you in order to enhance your experience.

If you do not want that we track your visit to our site you can disable tracking in your browser here:

Other external services

We also use different external services like Google Webfonts, Google Maps, and external Video providers. Since these providers may collect personal data like your IP address we allow you to block them here. Please be aware that this might heavily reduce the functionality and appearance of our site. Changes will take effect once you reload the page.

Google Webfont Settings:

Google Map Settings:

Google reCaptcha Settings:

Vimeo and Youtube video embeds:

Other cookies

The following cookies are also needed - You can choose if you want to allow them:

Privacy Policy

You can read about our cookies and privacy settings in detail on our Privacy Policy Page.

Privacy Policy
Accept settingsHide notification only