Is there anyway to use github / gitlab for downloading the docker image?

Viewed 230

Since Docker Hub only allows 1 private repo, I wonder if there is any way to use Github or Gitlab, etc., to download the images? for instance:

FROM git@github.com/username/repo
...
...
...
2 Answers

Very easy with an account on gitlab.com. GitLab provides a Docker registry linked to projects and you can have unlimited private projects:

  • Create a project my-docker-project
  • Go to Package and Registries > Container registries, you should see a few commands to access your registry
  • Connect your machine to this registry using a command like:
    # Will prompt for login/pass
    docker login registry.gitlab.com
    
    • You'll need an access token or deploy token with read_registry and write_registry scopes. You can generate one via your profile Preferences > Access token. Login is the token name and password the secret token provided.
  • You can now push Docker images with commands such as:
    # Push an image 
    docker push registry.gitlab.com/YourUsernameOrGroup/my-docker-project
    
    # Push an image on a sub-path
    docker push registry.gitlab.com/YourUsernameOrGroup/my-docker-project/myimage
    

You can then use the image in a Dockerfile by referencing its URL such as:

FROM registry.gitlab.com/YourUsernameOrGroup/my-docker-project

# ...

Of course the machine from which you build must be authenticated on related GitLab registry using docker login command above (or the project must be public)

both have excellent package registry services

For GitHub GPR For GitLab GCR

Both have excellent features like use it directly from Dockerfile as you want for example.

I have a public example, you can check it in Github with node.js which uses GPR to store the build image/package.

Related