Cannot Pull Private Repository Using Docker For Mac

Pull

Now that you have an OAuth token it's relatively easy to construct the HTTPS URL to pull or clone from your private repo(s). This can be done in the following fashion: git clone -b docker /myapp/ The:x-oauth-basic is where the magic happens. It should be noted that we are using personal access tokens which are a bit different than registered application tokens. Create a private registry. If you do not have a private registry, follow the steps in the documentation. On the Docker website. Alternatively, you can execute the following commands in a terminal to pull an image, get its ID, and push it to a new repository. Pull the official Nginx image. First, pull the public Nginx image to your local computer. Docker pull nginx Run the container locally. Execute following docker run command to start a local instance of the Nginx container interactively (-it) on port 8080.The -rm argument specifies that the container should be removed when you stop it. Docker run -it -rm -p 8080:80 nginx. At the end of this tutorial, you’ll have a secure, private Docker registry installed on your DigitalOcean Kubernetes cluster. Before you begin this tutorial, you’ll need: Docker installed on the machine that you’ll access your cluster from. For Ubuntu 18.04, visit How To Install and Use Docker on Ubuntu 18.04. Your private repo URL (note that free accounts get a public URL) Now that you’ve got a private repository, and a package, we can upload files to it. We do this using a tool called twine.

Table of Contents

Introduction

One common situation I have run into on different projects is how to instruct my Docker containers to automatically clone or pull from a private GitHub repository when they're built. The goal of this tutorial is to pull together various references I found into a single document for what I needed to do which is to spin up a rails app using code in a private repo on GitHub.

In this tutorial we will go through how to acquire an OAuth token from GitHub to access your repositories in an automated fashion and then use that in a Dockerfile to bring up a basic Ruby-on-Rails application using the Phusion Passenger 3.0 webserver.

Create GitHub OAuth Token

Developers have a few methods they can use to access their repositories on GitHub. Using personal access tokens allows you to forgo having to provide a username and password when making a request. This is the recommended approach to automating the synchronization of your code. It is also an easier method than hacking together one of the many SSH key solutions you might find elsewhere on the web.

These instructions assume that you host your repos with GitHub and that you have private repos you would like to pull or clone automatically. While being logged into your GitHub account you can obtain an OAuth token by navigating to Settings --> Applications --> Generate New Token.

Cannot Pull Private Repository Using Docker For Mac Windows 7

Be aware that when GitHub generates the token it will only show it to you once. When you browse away from the page you will not be able to view the token again therefore it's a good idea to make note of what it is before proceeding onto the Dockerfile steps. If you lose the token you will need to regenerate it. You can also use this interface to revoke tokens.

Cannot Pull Private Repository Using Docker For Mac Windows 10

Create the token so that it has the appropriate scope for what you require. The defaults should be fine for this example.

Dockerfile

Sierra

Now that you have an OAuth token it's relatively easy to construct the HTTPS URL to pull or clone from your private repo(s). This can be done in the following fashion:

The <token>:x-oauth-basic is where the magic happens. It should be noted that we are using personal access tokens which are a bit different than registered application tokens.

Now, let's turn to our Dockerfile:

In the first section we're instructing Docker to use Phusion's Ruby 1.9.3 image. If you don't have it locally it will be pulled down.

Docker Pull From Private Registry

We then clone our desired branch -- in our case docker -- to a new directory myapp at the root of the file system. All content is then copied over to the default /home/app location for the Passenger 3.0 container. The bundle install installs any required gems we may need.

Our Nginx configuration is taken from Passenger's Docker documentation, but looks like this:

We also add a few environment configuration files to ensure our Docker link names are exposed in Nginx, too.

Cannot Pull Private Repository Using Docker For Mac Osx

Once all that is done my_init is ran when the container spins up with 80 and 443 exposed.

Conclusion

Docker Private Repository

Hopefully this short tutorial helped you setup automatic GitHub repo pulls or clones using OAuth tokens. In future articles we will dive deeper into connecting our Ruby-on-Rails container to our two DB containers and connecting the DB containers to persistent storage volume containers.