简体   繁体   English

暴露在gitlab ci docker映像中运行的服务器

[英]Expose server running in gitlab ci docker image

I have a web application which is built and tested using gradle/gretty and gitlab-ci (with gitlab running on my own server) with a docker image. 我有一个使用gradle / gretty和gitlab-ci(在我自己的服务器上运行gitlab)和docker镜像构建和测试的Web应用程序。 This is working fine for unit tests. 这对于单元测试来说很好用。

But now I want users to test the web app in a browser. 但是现在我希望用户在浏览器中测试Web应用程序。 My idea: Create another gitlab-ci job (which is manually started) with a docker image, which utilizes grettys appStart to start a tomcat instance and leave it runnig, so that users can access it from their browser. 我的想法:使用docker映像创建另一个gitlab-ci作业(手动启动),该作业利用grettys appStart启动tomcat实例并保留其runnig,以便用户可以从其浏览器访问它。

The problem: How can I expose the server inside of the docker image to the outside world? 问题:如何将docker映像内部的服务器暴露给外界? I found hints how to do it, if you run a docker image standalone, but not how to do it when using docker with gitlab-ci. 我发现了提示,如果您独立运行docker映像,该怎么做,但在gitlab-ci中使用docker时,却没有如何做。

Or are there better approaches for doing what I try? 还是有更好的方法来做我尝试的事情?

My simple gitlab-ci.yml: 我的简单gitlab-ci.yml:

runServer:
  image: java:8-jdk
  script:
    - ./gradlew appStart
  when: manual

How can I expose the server inside of the docker image to the outside world? 如何将docker映像内部的服务器暴露给外界?

This can be done in two ways. 这可以通过两种方式完成。 They make the server's port in the container accessible on the host for the outside world: 它们使外部主机可以访问主机上容器中服务器的端口:

  1. Publish the server's port to the host by passing -p to docker run . 通过将-p传递给docker run ,将服务器的端口发布到主机。 More info is here . 更多信息在这里

     docker run -p hostPort:containerPort ... 
  2. Use Docker's " host networking " by passing --network host to docker run . 通过将使用多克的“ 主机网络--network hostdocker run More info is here . 更多信息在这里

     docker run --network host ... 

Why you could do that the jobs are not meant to run for a long time. 为什么可以这样做,这些工作并不能长期运行。 Luckil Gitlab has a feature called Review Apps , you should look into that and the new feature called Clusters . Luckil Gitlab有一个名为Review Apps的功能,您应该研究一下该功能以及名为Clusters的新功能。

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

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