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 registry.preview.openshift.com, 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).
$ <span class="s1">oc login https://api.preview.openshift.com --token=steves-special-token</span>
Authenticate with docker to enable it to access the OpenShift registry, using:
$ <span>docker login -u `oc whoami` -p `oc whoami -t` registry.preview.openshift.com</span>
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>
$ <span class="s1">docker tag sha256:c713a registry.preview.openshift.com/sspeiche-test1/MyImage</span>
Now we are ready to push the image, which is as simple as:
$ docker push registry.preview.openshift.com/sspeiche-test1/MyImage
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 172.30.47.227:5000/sspeiche-test1/nodejs-mongodb-example latest 33 minutes ago
MyImage 172.30.47.227:5000/sspeiche-test1/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 registry.preview.openshift.com/sspeiche-test1/nodejs-mongodb-example
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 registry.preview.openshift.com/sspeiche-test1/nodejs-mongodb-example
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 http://0.0.0.0:8080
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:
- OpenShift Concept: Image Streams
- oc import-image
- OpenShift: Accessing the Registry
저자 소개
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
가상화
온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래