适当的Docker配置,适用于同时在本地Docker容器上运行的GitLab和Runner。

huangapple go评论99阅读模式
英文:

Proper docker configuration for both gitlab & a runner running on local docker containers

问题

以下是您要翻译的内容:

"I am trying to get a docker compose file to run a local gitlab + gitlab-runner and it seems I have a naming / network issue.

What IS working:

  • I have gitlab and the gitlab runner up and running
  • gitlab works as a remote for local repos, cloning, pushing & so on.
  • gitlab-runner works fine as a runner for my projects on other gitlab servers (tested on gitlab.com)
  • I can register the runner for a project in my gitlab container, view the config, trigger a job (the docker executor starts and gets the image to run the environment)

What IS NOT working:

  • The job fails when trying to get source from the project repository with the following error message (the repository url it tries to access is correct)
    > fatal: unable to access 'http://gitlab:8081/cours/pipelinediscover.git/': Failed to connect to gitlab port 8081 after 131012 ms: Couldn't connect to server

Here are

  1. My current docker compose yml
  1. version: '3.6'
  2. services:
  3. gitlab:
  4. image: 'gitlab/gitlab-ce:latest'
  5. restart: always
  6. container_name: gitlab
  7. hostname: 'gitlab'
  8. environment:
  9. GITLAB_OMNIBUS_CONFIG:
  10. external_url 'http://gitlab:8081'
  11. # Add any other gitlab.rb configuration here, each on its own line
  12. ports:
  13. - '8081:8081'
  14. - '4443:443'
  15. - '2222:22'
  16. volumes:
  17. - './config:/etc/gitlab'
  18. - './logs:/var/log/gitlab'
  19. - './data:/var/opt/gitlab'
  20. shm_size: '1024m'
  21. runner:
  22. image: 'gitlab/gitlab-runner:latest'
  23. restart: always
  24. volumes:
  25. - './gitlab-runner/config:/etc/gitlab-runner'
  26. - '/var/run/docker.sock:/var/run/docker.sock'
  27. container_name: gitlab-runner

n.b I had to edit my host /etc/hosts file to be able to access the interface at gitlab:8081 and not localhost:8081 that may not be ideal but if gitlab is configured with external_url at "localhost:8081" then the gitlab-runner cannot interface with it at all. There might be some sweet spot in both docker & gitlab config I missed for domain/network naming.

  1. The runner toml config :
  1. concurrent = 5
  2. check_interval = 0
  3. shutdown_timeout = 0
  4. [session_server]
  5. session_timeout = 1800
  6. [[runners]]
  7. name = "05f411d789cb"
  8. url = "http://gitlab:8081/"
  9. id = 6
  10. token = "9HXz2_XQzLCpqPiTqDUZ"
  11. token_obtained_at = 2023-03-31T07:09:00Z
  12. token_expires_at = 0001-01-01T00:00:00Z
  13. executor = "docker"
  14. [runners.cache]
  15. MaxUploadedArchiveSize = 0
  16. [runners.docker]
  17. tls_verify = false
  18. image = "alpine:latest"
  19. privileged = false
  20. disable_entrypoint_overwrite = false
  21. oom_kill_disable = false
  22. disable_cache = false
  23. volumes = ["/cache"]
  24. shm_size = 0
英文:

I am trying to get a docker compose file to run a local gitlab + gitlab-runner and it seems I have a naming / network issue.

What IS working :

  • I have gitlab and the gitlab runner up and running
  • gitlab works as a remote for local repos, cloning, pushing & so on.
  • gitlab-runner works fine as a runner for my projects on other gitlab servers (tested on gitlab.com)
  • I can register the runner for a project in my gitlab container, view the config, trigger a job (the docker executor starts and gets the image to run the environment)

What IS NOT working :

  • The job fails when trying to get source from the project repository with the following error message (the repository url it tries to access is correct)
    > fatal: unable to access 'http://gitlab:8081/cours/pipelinediscover.git/': Failed to connect to gitlab port 8081 after 131012 ms: Couldn't connect to server

Here are

  1. My current docker compose yml
  1. version: '3.6'
  2. services:
  3. gitlab:
  4. image: 'gitlab/gitlab-ce:latest'
  5. restart: always
  6. container_name: gitlab
  7. hostname: 'gitlab'
  8. environment:
  9. GITLAB_OMNIBUS_CONFIG:
  10. external_url 'http://gitlab:8081'
  11. # Add any other gitlab.rb configuration here, each on its own line
  12. ports:
  13. - '8081:8081'
  14. - '4443:443'
  15. - '2222:22'
  16. volumes:
  17. - './config:/etc/gitlab'
  18. - './logs:/var/log/gitlab'
  19. - './data:/var/opt/gitlab'
  20. shm_size: '1024m'
  21. runner:
  22. image: 'gitlab/gitlab-runner:latest'
  23. restart: always
  24. volumes:
  25. - './gitlab-runner/config:/etc/gitlab-runner'
  26. - '/var/run/docker.sock:/var/run/docker.sock'
  27. container_name: gitlab-runner

n.b I had to edit my host /etc/hosts file to be able to access the interface at gitlab:8081 and not localhost:8081 that may not be ideal but if gitlab is configured with external_url at "localhost:8081" then the gitlab-runner cannot interface with it at all. There might be some sweet spot in both docker & gitlab config I missed for domain/network naming.

  1. The runner toml config :
  1. concurrent = 5
  2. check_interval = 0
  3. shutdown_timeout = 0
  4. [session_server]
  5. session_timeout = 1800
  6. [[runners]]
  7. name = "05f411d789cb"
  8. url = "http://gitlab:8081/"
  9. id = 6
  10. token = "9HXz2_XQzLCpqPiTqDUZ"
  11. token_obtained_at = 2023-03-31T07:09:00Z
  12. token_expires_at = 0001-01-01T00:00:00Z
  13. executor = "docker"
  14. [runners.cache]
  15. MaxUploadedArchiveSize = 0
  16. [runners.docker]
  17. tls_verify = false
  18. image = "alpine:latest"
  19. privileged = false
  20. disable_entrypoint_overwrite = false
  21. oom_kill_disable = false
  22. disable_cache = false
  23. volumes = ["/cache"]
  24. shm_size = 0

答案1

得分: 1

It looks like you haven't configured networking between the services in your compose file.

If you configure both services to use the same network (or specify depends_on: [gitlab] for the runner service) the name should be resolvable by default and the connection will be allowed.

  1. services:
  2. gitlab:
  3. networks:
  4. - appnet
  5. # ...
  6. runner:
  7. # ...
  8. networks:
  9. - appnet
  10. networks:
  11. appnet:

或者

  1. services:
  2. # ...
  3. runner:
  4. depends_on: [gitlab]
  5. # ...
英文:

It looks like you haven't configured networking between the services in your compose file.

If you configure both services to use the same network (or specify depends_on: [gitlab] for the runner service) the name should be resolvable by default and the connection will be allowed.

  1. services:
  2. gitlab:
  3. networks:
  4. - appnet
  5. # ...
  6. runner:
  7. # ...
  8. networks:
  9. - appnet
  10. networks:
  11. appnet:

Or

  1. services:
  2. # ...
  3. runner:
  4. depends_on: [gitlab]
  5. # ...

huangapple
  • 本文由 发表于 2023年3月31日 15:45:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75896041.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定