Openshift-我可以使用Openshift运行docker客户端命令(例如docker push)吗? [英] Openshift - can I run docker client commands (like docker push) using Openshift?

查看:105
本文介绍了Openshift-我可以使用Openshift运行docker客户端命令(例如docker push)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

拥有Docker主机后,使用Docker即可轻松进行.您将Docker客户端与Docker主机(引擎)连接起来.然后,在Jenkins构建服务器上构建和部署(复杂)docker映像的过程类似于以下一系列命令:

Working with Docker is easy when you have a docker host. You connect the Docker client with a Docker host (engine). Then the process of building and deploying a (complex) docker image is like this series of commands on a Jenkins build server:

  • Maven全新安装=>构建您的WAR文件
  • Docker build =>创建一个包含WAR应用程序文件的Wildfly映像
  • Docker标记=>标记新图像
  • Docker push =>将图像推送到docker hub
  • Docker run ==>在docker主机上安装并运行docker镜像.

Openshift Starter可以这样工作吗?答案:是的,此容器即服务(CAAS)选项是可能的.

Can Openshift Starter work like this? The answer: yes, this Container As A Service (CAAS) option is possible.

在下面的步骤中,我创建一个由2个图像组成的项目:MySql和由Wildfly服务器托管的SpringBoot/Angular/Hibernate.当然,这也适用于Spring Boot JAR应用程序.

In the steps below I create a project consisting of 2 images: MySql and SpringBoot/Angular/Hibernate hosted by a Wildfly server. This works of course also for a Spring Boot JAR application.

您从本地运行的Docker守护程序开始.我是通过Docker Quickstart Terminal执行此操作的.我仅将minishift用于本地测试-因此在这种情况下不使用.

You start with a local running Docker daemon. I do this via Docker Quickstart Terminal. I use minishift only for local testing - so not in this case.

步骤1 :创建一个项目和1个MySql应用程序.

Step 1: create a project and 1 MySql application.

这可以在没有docker的情况下通过Openshift Web控制台完成.您也可以使用oc new-proect命令.

This can be done without docker via the Openshift web console. You can also use the oc new-proect command.

第2步:登录到openshift项目.在在线控制台中,单击顶部栏(右侧)上的问号.选择命令行工具".您可以通过右侧的图标将登录命令复制到剪贴板.

Step 2: login to the openshift project. In the online console click on the question mark on the top bar (on the right). Select the "command line tools". You can copy the login command to your clipboard via the icon to the right.

$ oc登录等...(第一个剪贴板图标,粘贴整个命令).

$ oc login etc ... (first clipboard-icon, paste the entire command).

步骤3 :登录到您的Docker注册表.在这种情况下,请检查openshift在线控制台.

Step 3: Login to your docker registry. In this case check the openshift online console.

$ docker login -u`oc whoami` -p`oc whoami --show-token`registry.pro-us-east-1.openshift.com

$ docker login -u `oc whoami` -p `oc whoami --show-token` registry.pro-us-east-1.openshift.com

注意:请勿将端口号用作后缀openshift:443 !!

NOTICE: don't use the port number as the suffix openshift:443 !!

步骤4::在本地或在构建服务器上(使用Jenkins)构建并标记图像.

Step 4: Build and tag the image locally or on the build server (with Jenkins).

$ mvn全新安装-创建war文件.您可以将其称为"ROOT.war".

$ mvn clean install -- which creates the war file. You can call it 'ROOT.war'.

$ docker build -t myproject/mynewapplication:latest.

$ docker build -t myproject/mynewapplication:latest .

$ docker标签myproject/mynewapplication Registry.pro-us-east-1.openshift.com/myproject/mynewapplication

$ docker tag myproject/mynewapplication registry.pro-us-east-1.openshift.com/myproject/mynewapplication

如果您输入的名称不正确,一会儿您将无法推送图像.所以不要(!)写pro-us-east1.它是pro-us-east-1,等等

If you write the name not correct, in a moment you will not be able to push the image. So don't (!) write pro-us-east1. It is pro-us-east-1, etc.

Dockerfile位于Maven项目文件夹中. dockerfile可能看起来像:

The Dockerfile is in the Maven project folder. The dockerfile could look like:

FROM jboss/wildfly
COPY target/ROOT.war /opt/jboss/wildfly/standalone/deployments/
# CMD - use the default wildfly default start command

一种更有效的内存存储方式是:

A much more memory efficient way is:

FROM openjdk:8-jdk-alpine
ENV JAVA_APP_JAR your.jar
ENV AB_OFF true
EXPOSE 8080
ADD target/$JAVA_APP_JAR /deployments/
CMD ["java","-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-jar","/deployments/your.jar"]

最后的设置将极大地改善/平衡您的内存使用量.就我而言,将运行中的容器从600MB +减少到300MB左右就可以了!

The last settings will improve/balance your memory usage tremenduously. In my case reducing the running container from 600MB+ to around 300MB running fine!

第5步:将图像推送到内部Openshift存储库

Step 5: Push the image to the internal Openshift repository

$ docker push Registry.pro-us-east-1.openshift.com/myproject/mynewapplication

$ docker push registry.pro-us-east-1.openshift.com/myproject/mynewapplication

步骤6-A.1 :通过new-app命令从现有docker映像创建应用程序.仅在创建应用程序时第一次执行此操作.

Step 6-A.1: Create an application from an existing docker image via the new-app command. Do this only the first time while creating the application.

$ oc new-app mynewapplication

$ oc new-app mynewapplication


--> Found image 1233123223 (About an hour old) in image stream "myproject/mynewapplication" under tag "latest" for "mynewapplication"
... This image will be deployed in deployment config "mynewapplication"
--> Creating resources ...
    deploymentconfig "mynewapplication" created
    service "mynewapplication" created
--> Success
    Run 'oc status' to view your app. 

步骤6-A.2 :有关初始化设置的信息,请参见下文.部署应用程序/Web服务器时,请创建一个路由",以便客户端可以访问该应用程序.由于必须执行一次,因此通过控制台(应用程序">路由")进行设置是一个不错的选择.示例:使用标准证书使您的网站仅可用于https:(1)使用目标端口8080(运行HTTP服务器的位置),(2)选中安全路由"选项,(3)保持TLS终止为Edge. (4)对于不安全的流量,请选择重定向"选项并...创建您的路线.稍等片刻,您就有一个HTTPS站点.

Step 6-A.2: See below for initializing the settings. When deploying an application / web server, create a 'route' so that the client can access the application. Because this has to be done once, setting it up via the console (Applications > Routes) is a good alternative. Example: make your website available only for https with the standard certificate: (1) use target port 8080 (where your http server is running), (2) tick the Secure route option, (3) keep the TLS Termination to Edge. (4) for insecure traffic choose the Redirect option and ... create your route. Wait a while and you have a HTTPS site.

步骤6-B :更新图像时:推送现有图像时,不会进行自动重新部署.您可以通过在线控制台或通过以下命令来开始新的部署:

Step 6-B: When updating the image: When you push an existing image, then there will not be an automatic redeploy. You can start a new deploy via the online console or via the command:

$ oc最新推出dc/mynewapplication-n myproject

$ oc rollout latest dc/mynewapplication-n myproject

要检查部署结果:

$ oc状态

检查是否MySql容器正在运行:

To check whether e.g. the MySql container is running:

$ oc获取豆荚

获取Mysql容器的名称.

Get the name of the Mysql container.

$ oc rsh容器名称

$ oc rsh container-name

您将看到您是否真的可以访问数据库.

And you will see whether you can really access the database.

备注: 使用Openshift Starter/Original的备注:很高兴Openshift允许我们尝试免费的Starter版本.当然,对资源的使用有一系列限制.注意将部署"策略设置为重新创建". 滚动"策略当然更好,但会消耗更多资源.我将MySql图像的资源大小通常设置为420Mi,而Wildfly图像的资源大小设置为600Mi.欢迎提出建议!

Remarks: Remark for using Openshift Starter/Original: It is nice that Openshift allows us to experiment with the free Starter version. There are of course a set of restrictions on the usage of the resources. Take care to set the Deploy strategy to 'Recreate'. The 'Rolling' strategy is of course better, but consumes a lot more resources. I set the resource size for the MySql image typically to 420Mi and the Wildfly image to 600Mi. Suggestions are welcome!

推荐答案

您可以登录到OpenShift的内部图像注册表,然后将图像直接推送到其中.您需要先标记图像,使其与推送图像的项目名称匹配.有关更多详细信息,请参见:

You can login to the internal image registry of OpenShift and push your image directly to it. You need to tag the image first so it matches the name of the project where pushing it. For more details see:

一旦推送到内部映像注册表,您就可以使用oc new-app或Web控制台从该映像进行部署.

Once pushed to the internal image registry you can then deploy from that image using oc new-app or the web console.

这篇关于Openshift-我可以使用Openshift运行docker客户端命令(例如docker push)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆