简体   繁体   English

如何在 gitlab-runner 中发布端口?

[英]How can I publish a port in a gitlab-runner?

I want to deploy a container on my server with gitlab-runner (docker executor) and then get response from my local browser.我想用 gitlab-runner(docker executor)在我的服务器上部署一个容器,然后从我的本地浏览器获得响应。

I have the most simple dockerfile that start an nginx:我有最简单的 dockerfile 启动 nginx:

FROM nginx:alpine
COPY /nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

And my nginx config looks like this:我的 nginx 配置如下所示:

server {
    listen 80;
    location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
        try_files $uri $uri/ /index.html =404;
    }

}

Here's my.gitlab.yml:这是我的.gitlab.yml:

image: docker:latest
services: 
  - docker:dind

variables:
  WORK_DIR: ${CI_PROJECT_NAME}
  BRANCH: ${CI_COMMIT_REF_NAME}
  REGISTRY: registry.gitlab.com/myusername/cicdtest

stages:
  - build
  - deploy

build_project:
    stage: build
    script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - docker build -t $REGISTRY .
        - docker push $REGISTRY



deploy_project:
    stage: deploy
    script:
        - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
        - docker pull $REGISTRY
        - docker stop $(docker ps -a -q) || true && docker rm $(docker ps -a -q) || true
        - docker run --name=$BRANCH -p 80:80 -itd $REGISTRY   

And my config.toml:还有我的 config.toml:

[[runners]]
  name = "name1"
  url = "https://gitlab.com/"
  token = "secret"
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
  [runners.docker]
    tls_verify = false
    image = "docker:alpine"
    privileged = true
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
    shm_size = 0

By the way everything with docker and nginx works fine in localhost.顺便说一句,docker 和 nginx 的一切都可以在 localhost 中正常工作。

Now when I push to repo all the pipelines get the passed status and every line is executed fine but when I try to access my container from my local browser with url 185.xxx.xx.xx I can't get any responses.现在,当我推送回购时,所有管道都获得了通过状态并且每一行都执行得很好,但是当我尝试使用 url 185.xxx.xx.xx从本地浏览器访问我的容器时,我无法得到任何响应。 It's like gitlab-runner didn't publish any ports.这就像 gitlab-runner 没有发布任何端口。

Can't help your with a solution right now but Im here to help.现在无法为您提供解决方案,但我在这里为您提供帮助。 At first please inspect the running docker container and see if your idea, that the ports are not set up correctly, is right:首先请检查正在运行的 docker 容器,看看您的想法是否正确,即端口设置不正确:

[docker inspect [OPTIONS] NAME|ID [NAME|ID...]]

https://docs.docker.com/engine/reference/commandline/inspect/ https://docs.docker.com/engine/reference/commandline/inspect/

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

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