简体   繁体   English

Openshift - 我可以使用 Openshift 运行 docker 客户端命令(如 docker 推送)吗?

[英]Openshift - can I run docker client commands (like docker push) using Openshift?

Working with Docker is easy when you have a docker host.当您拥有 docker 主机时,使用 Docker 很容易。 You connect the Docker client with a Docker host (engine).您将 Docker 客户端与 Docker 主机(引擎)连接。 Then the process of building and deploying a (complex) docker image is like this series of commands on a Jenkins build server:然后构建和部署一个(复杂的)docker 镜像的过程就像在 Jenkins 构建服务器上的这一系列命令:

  • Maven clean install => builds your WAR file Maven 全新安装 => 构建您的 WAR 文件
  • Docker build => creates a Wildfly image with the WAR application file in it Docker build => 创建一个包含 WAR 应用程序文件的 Wildfly 映像
  • Docker tag => tags the new image Docker tag => 标记新图像
  • Docker push => pushes the image to a docker hub Docker push => 将图像推送到 docker hub
  • Docker run ==> installs and runs the docker image on the docker host. Docker run ==> 在 docker 主机上安装并运行 docker 映像。

Can Openshift Starter work like this? Openshift Starter 可以这样工作吗? The answer: yes, this Container As A Service (CAAS) option is possible.答案:是的,这个容器即服务 (CAAS) 选项是可行的。

COMPLETE SOLUTION:完整的解决方案:

In the steps below I create a project consisting of 2 images: MySql and SpringBoot/Angular/Hibernate hosted by a Wildfly server.在下面的步骤中,我创建了一个由 2 个图像组成的项目:MySql 和由 Wildfly 服务器托管的 SpringBoot/Angular/Hibernate。 This works of course also for a Spring Boot JAR application.这当然也适用于 Spring Boot JAR 应用程序。

You start with a local running Docker daemon.您从本地运行的 Docker 守护进程开始。 I do this via Docker Quickstart Terminal.我通过 Docker 快速启动终端执行此操作。 I use minishift only for local testing - so not in this case.我仅将 minishift 用于本地测试 - 所以在这种情况下不使用。

Step 1 : create a project and 1 MySql application.第 1 步:创建项目和 1 MySql 应用程序。

This can be done without docker via the Openshift web console.这可以通过 Openshift web 控制台在没有 docker 的情况下完成。 You can also use the oc new-proect command.您还可以使用 oc new-proect 命令。

Step 2 : login to the openshift project.第 2 步:登录到 openshift 项目。 In the online console click on the question mark on the top bar (on the right).在在线控制台中,单击顶部栏(右侧)上的问号。 Select the "command line tools". Select 《命令行工具》。 You can copy the login command to your clipboard via the icon to the right.您可以通过右侧的图标将登录命令复制到剪贴板。

$ oc login etc... (first clipboard-icon, paste the entire command). $ oc login etc...(第一个剪贴板图标,粘贴整个命令)。

Step 3 : Login to your docker registry.第 3 步:登录您的 docker 注册表。 In this case check the openshift online console.在这种情况下,请检查 openshift 在线控制台。

$ 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

NOTICE: don't use the port number as the suffix openshift:443 !!注意:不要使用端口号作为后缀 openshift:443 !!

Step 4: Build and tag the image locally or on the build server (with Jenkins).第 4 步:在本地或在构建服务器上(使用 Jenkins)构建和标记图像。

$ mvn clean install -- which creates the war file. $ mvn clean install -- 创建 war 文件。 You can call it 'ROOT.war'.你可以称它为“ROOT.war”。

$ docker build -t myproject/mynewapplication:latest. $ docker build -t myproject/mynewapplication:latest.

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

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.所以不要(.)写pro-us-east1,就是pro-us-east-1。 etc.等等

The Dockerfile is in the Maven project folder. Dockerfile 在 Maven 项目文件夹中。 The dockerfile could look like: dockerfile 可能如下所示:

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: memory 更有效的方法是:

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"]

The last settings will improve/balance your memory usage tremenduously.最后的设置将极大地改善/平衡您的 memory 使用。 In my case reducing the running container from 600MB+ to around 300MB running fine!在我的例子中,将正在运行的容器从 600MB+ 减少到大约 300MB 运行良好!

Step 5 : Push the image to the internal Openshift repository第 5 步:将镜像推送到内部 Openshift 存储库

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

Step 6-A.1 : Create an application from an existing docker image via the new-app command.步骤 6-A.1 :通过 new-app 命令从现有的 docker 图像创建应用程序。 Do this only the first time while creating the application.仅在创建应用程序时第一次执行此操作。

$ oc new-app mynewapplication $ oc 新应用程序 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. 

Step 6-A.2 : See below for initializing the settings.步骤 6-A.2 :见下文初始化设置。 When deploying an application / web server, create a 'route' so that the client can access the application.在部署应用程序/web 服务器时,创建一个'路由',以便客户端可以访问该应用程序。 Because this has to be done once, setting it up via the console (Applications > Routes) is a good alternative.因为这必须完成一次,所以通过控制台(Applications > Routes)设置它是一个很好的选择。 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.示例:使用标准证书使您的网站仅适用于 https:(1) 使用目标端口 8080(您的 http 服务器正在运行的位置),(2) 勾选安全路由选项,(3) 将 TLS 终止保留为边缘。 (4) for insecure traffic choose the Redirect option and... create your route. (4) 对于不安全的流量,选择重定向选项并...创建您的路线。 Wait a while and you have a HTTPS site.稍等片刻,您将拥有一个 HTTPS 站点。

Step 6-B : When updating the image: When you push an existing image, then there will not be an automatic redeploy.步骤 6-B :更新镜像时:当您推送现有镜像时,不会自动重新部署。 You can start a new deploy via the online console or via the command:您可以通过在线控制台或通过以下命令开始新的部署:

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

To check the results of the deployment:检查部署结果:

$ oc status $ oc 状态

To check whether eg the MySql container is running:检查 MySql 容器是否正在运行:

$ oc get pods $ oc 获取 pod

Get the name of the Mysql container.获取 Mysql 容器的名称。

$ oc rsh container-name $ oc rsh 容器名称

And you will see whether you can really access the database.你会看到你是否真的可以访问数据库。

Remarks : Remark for using Openshift Starter/Original: It is nice that Openshift allows us to experiment with the free Starter version.备注:使用 Openshift Starter/Original 的备注:很高兴 Openshift 允许我们试用免费的 Starter 版本。 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.我通常将 MySql 图像的资源大小设置为 420Mi,将 Wildfly 图像设置为 600Mi。 Suggestions are welcome!欢迎提出建议!

You can login to the internal image registry of OpenShift and push your image directly to it.您可以登录到 OpenShift 的内部镜像注册表并将您的镜像直接推送到它。 You need to tag the image first so it matches the name of the project where pushing it.您需要先标记图像,使其与推送它的项目名称相匹配。 For more details see:有关详细信息,请参阅:

Once pushed to the internal image registry you can then deploy from that image using oc new-app or the web console.一旦推送到内部映像注册表,您就可以使用oc new-app或 web 控制台从该映像进行部署。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM