简体   繁体   中英

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. This is working fine for unit tests.

But now I want users to test the web app in a browser. 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.

The problem: How can I expose the server inside of the docker image to the outside world? 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.

Or are there better approaches for doing what I try?

My simple 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?

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 . More info is here .

     docker run -p hostPort:containerPort ... 
  2. Use Docker's " host networking " by passing --network host to docker 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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