DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Running SpringBoot Application On OpenShift
  • 7 Ways of Containerizing Your Node.js Application
  • Auto-Scaling a Spring Boot Native App With Nomad
  • Manage Microservices With Docker Compose

Trending

  • Unlocking AI Coding Assistants Part 4: Generate Spring Boot Application
  • A Developer's Guide to Mastering Agentic AI: From Theory to Practice
  • Breaking Bottlenecks: Applying the Theory of Constraints to Software Development
  • Unlocking the Benefits of a Private API in AWS API Gateway
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Deploying Docker Images to OpenShift

Deploying Docker Images to OpenShift

We take a look at how to deploy a Docker image from DockerHub into RedHat's OpenShift environment, bringing added functionality along the way.

By 
Alex Soto user avatar
Alex Soto
·
May. 26, 17 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
39.5K Views

Join the DZone community and get the full member experience.

Join For Free

OpenShift is RedHat's cloud development Platform-as-a-Service (PaaS). It uses Kubernetes for container orchestration (so you can use OpenShift as your Kubernetes implementation) while providing some features missed in Kubernetes, such as automation of the build process of the containers, health management, dynamic provision storage, or multi-tenancy, to cite a few.

In this post, I am going to explain how you can deploy a Docker image from DockerHub into an OpenShift instance.

It is important to note that OpenShift offers other ways to create and deploy a container into its infrastructure. You can read more here, but as read in the previous paragraph, in this case, I am going to show you how to deploy already-created Docker images from DockerHub.

The first thing to do is create an account in OpenShift Online. It is free and, for the sake of this post, is enough. Of course, you can use any other OpenShift approach, like OpenShift Origin.

After that, you need to log into OpenShift cluster. In the case of OpenShift Online, use the token provided:

oc login https://api.starter-us-east-1.openshift.com --token=xxxxxxx 

Then you need to create a new project inside OpenShift.

oc new-project villains 

You can understand a project as a Kubernetes namespace with additional features.

Then, let's create a new application within the previous project based on a Docker image published on DockerHub. This example is a VertX application where you can get crimes from several fictional villains — from Lex Luthor to Gru.

oc new-app lordofthejars/crimes:1.0 --name crimes 

In this case, a new app called crimes is created based on the lordofthejars/crimes:1.0 image. After running the previous command, a new pod running the previous image + a service +  a replication controller is created.

After that, we need to create a route so the service is available to the public Internet.

oc expose svc crimes --name=crimeswelcome 

The last step is just to get the version of the service from the browser. In my case, it was: http://crimeswelcome-villains.1d35.starter-us-east-1.openshiftapps.com/version

Notice that you need to change the public host with the one generated by your router and then append the version. You can find the public URL by going to the OpenShift dashboard, at the top of the pods definition.

Ok, now you'll get a 1.0, which is the version we have deployed. Now suppose you want to update to next version of the service, to version 1.1, so you need to run next commands to deploy next version of crimes service container, which is pushed at Docker Hub.

oc import-image crimes:1.1 --from=lordofthejars/crimes:1.1 

With the previous command, you are configuring internal OpenShift Docker Registry with next Docker image to release.

Then let's prepare the application so when next rollout command is applied, the new image is deployed:

oc patch dc/crimes -p '{"spec": { "triggers":[ {"type": "ConfigChange", "type": "ImageChange" , "imageChangeParams": {"automatic": true, "containerNames":["crimes"],"from": {"name":"crimes:1.1"}}}]}}'


And finally you can do the rollout of the application by using:

oc rollout latest dc/crimes 

After a few seconds, you can again go to http://crimeswelcome-villains.1d35.starter-us-east-1.openshiftapps.com/version (of course, change the host with your host), and the version you'll get is 1.1.

Finally, what happens if this new version contains a bug and you want to do a rollback of the deployment to previous version? Easy. Just run next command:

oc rollback crimes-1 

And the previous version is going to be deployed again, so after a few seconds, you can go again to /version and you'll see 1.0 version again.

Finally, if you want to delete the application to have a clean cluster, run:

oc delete all --all  

So as you can see, it is really easy to deploy container images from DockerHub to OpenShift. Notice that there are other ways to deploy our application into OpenShift, in this post I have just shown you one.

Commands can be found here. 

Docker (software) OpenShift Kubernetes application

Published at DZone with permission of Alex Soto, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Running SpringBoot Application On OpenShift
  • 7 Ways of Containerizing Your Node.js Application
  • Auto-Scaling a Spring Boot Native App With Nomad
  • Manage Microservices With Docker Compose

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!