Getting Started With Docker Registry

OpenShift takes care of moving around your images with the internal docker registry. There are cases where it makes sense to either directly push docker formatted images to the registry or you’ll want to pull the images out of the registry to use in other contexts, such as local development.

With the recent announcement of the Dev Preview of the Next Generation of OpenShift Online which gives developers a hands on preview of the OpenShift platform in a hosted environment that includes access to the internal registry. Let’s take a look at how one can interact with this registry directly with the docker command. For the purposes of this post, I’ll be using Docker Machine from my MacBook to have an active docker daemon to work with.

Why would you want to push a new image to the registry? There are many reasons, the scenario I’m going to look at is based on performing a native docker build outside of OpenShift (for example on my laptop) and pushing the resulting image to the registry.

The registry URL is simply, pretty easy to remember.

Push it

First make sure your docker is setup properly

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE

Next, make sure you are logged into OpenShift from the CLI. An easy way to do this is from browser
interface, go to help icon drop down and select “Command Line Tools” and from that page you can copy the oc login command with valid token (see image to the right).

oc login --token=steves-special-token

Authenticate with docker to enable it to access the OpenShift registry, using:

docker login -u `oc whoami` -p `oc whoami -t`

Note: you could have just plugged in the token if you had that, though if you use the CLI often you are probably already logged in.

Next I’ve done a docker build and now have an image in my local repo.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>              <none>              sha256:59c9c        2 minutes ago       317.9 MB
centos              latest              sha256:904d6        13 days ago         196.8 MB
MyImage             latest              sha256:c713a        11 days ago         18.5 MB

Next we tag the image. The tag needs to be of the form: <registry URL>/<project name>/<image name>

docker tag sha256:c713a

Now we are ready to push the image, which is as simple as:

docker push

We can check the image streams that my project has by checking in the browser interface or just using oc as

$ oc get is
NAME                     DOCKER REPO                                                TAGS      UPDATED
nodejs-mongodb-example   latest    33 minutes ago
MyImage                          latest    6 minutes ago

Well that was cool and pretty straightforward.

Run it

Now let’s run this thing, we can do this by

$ oc new-app MyImage --name=MyApp
 --> Found image 28e0bb7 (19 minutes old) in image stream MyImage under tag "latest" for "MyImage"

* This image will be deployed in deployment config "MyApp"
 * The image does not expose any ports - if you want to load balance or send traffic to this component
 you will need to create a service with 'expose dc/MyApp --port=[port]' later

--> Creating resources with label app=MyApp ...
 deploymentconfig "MyApp" created
 --> Success
 Run 'oc status' to view your app.

That’s it, my container was built locally and then pushed directly into OpenShift’s registry. Then launched the image in OpenShift.

Push it

Now, let’s pull down a built image by OpenShift and run it locally. I’ve already built the nodejs-mongodb-example quickstart. So  this makes it easy to just grab the result as:

$ docker pull

Notice the name of the image is just the name of the image stream we saw before from the oc get is command.

Run it

docker run
npm info it worked if it ends with ok
npm info using npm@2.14.13
npm info using node@v0.10.40
npm info prestart nodejs-ex@0.0.1
npm info start nodejs-ex@0.0.1
> nodejs-ex@0.0.1 start /opt/app-root/src
> node server.js
Server running on

I know what you are thinking: “Wait, what? That’s all we had to do?” Yes, it is that easy.

Some helpful resources if you want to know more:

News, OpenShift Online
, , ,
Comments are closed.