英文:
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
- My current docker compose yml
version: '3.6'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
restart: always
container_name: gitlab
hostname: 'gitlab'
environment:
GITLAB_OMNIBUS_CONFIG:
external_url 'http://gitlab:8081'
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '8081:8081'
- '4443:443'
- '2222:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
shm_size: '1024m'
runner:
image: 'gitlab/gitlab-runner:latest'
restart: always
volumes:
- './gitlab-runner/config:/etc/gitlab-runner'
- '/var/run/docker.sock:/var/run/docker.sock'
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.
- The runner toml config :
concurrent = 5
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "05f411d789cb"
url = "http://gitlab:8081/"
id = 6
token = "9HXz2_XQzLCpqPiTqDUZ"
token_obtained_at = 2023-03-31T07:09:00Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.docker]
tls_verify = false
image = "alpine:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
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
- My current docker compose yml
version: '3.6'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
restart: always
container_name: gitlab
hostname: 'gitlab'
environment:
GITLAB_OMNIBUS_CONFIG:
external_url 'http://gitlab:8081'
# Add any other gitlab.rb configuration here, each on its own line
ports:
- '8081:8081'
- '4443:443'
- '2222:22'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
shm_size: '1024m'
runner:
image: 'gitlab/gitlab-runner:latest'
restart: always
volumes:
- './gitlab-runner/config:/etc/gitlab-runner'
- '/var/run/docker.sock:/var/run/docker.sock'
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.
- The runner toml config :
concurrent = 5
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "05f411d789cb"
url = "http://gitlab:8081/"
id = 6
token = "9HXz2_XQzLCpqPiTqDUZ"
token_obtained_at = 2023-03-31T07:09:00Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
[runners.cache]
MaxUploadedArchiveSize = 0
[runners.docker]
tls_verify = false
image = "alpine:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
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.
services:
gitlab:
networks:
- appnet
# ...
runner:
# ...
networks:
- appnet
networks:
appnet:
或者
services:
# ...
runner:
depends_on: [gitlab]
# ...
英文:
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.
services:
gitlab:
networks:
- appnet
# ...
runner:
# ...
networks:
- appnet
networks:
appnet:
Or
services:
# ...
runner:
depends_on: [gitlab]
# ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论