2017-03-21 74 views
1

我有一臺私人的Gitlab託管在我自己的機器上。我將代碼存儲在Gitlab中,並希望從Dockerfile構建Docker鏡像,然後將其推送到Amazon ECR註冊表。不幸的是,這並不工作,因爲它拋出一個錯誤:建設並推動碼頭圖像從Gitlab-CI到亞馬遜AWS ECR

Flag --email has been deprecated, will be removed in 1.13. 
Cannot connect to the Docker daemon. Is the docker daemon running on this host? 
/dev/mapper/control: open failed: Operation not permitted 
Failure to communicate with kernel device-mapper driver. 
Check that device-mapper is available in the kernel. 
Command failed 
mount: permission denied 
Could not mount /sys/kernel/security. 
AppArmor detection and --privileged mode might break. 
mkdir: cannot create directory '/sys/fs/cgroup/name=systemd': Read-only file system 
mount: mount point /sys/fs/cgroup/name=systemd is not a directory 
ln: failed to create symbolic link '/sys/fs/cgroup/systemd/name=systemd': Read-only file system 

Timed out trying to connect to internal docker host. 

的gitlab-CI代碼如下所示:

stages: 
    - build 

build_airflow: 
    stage: build 
    only: [master, develop] 
    image: gitlab/dind:latest 
    services: 
    - docker:dind 
    script: 
    - APP=airflow 
    - sh ./scripts/login-ecs.sh my_fancy_project 

的login-ecs.sh腳本是執行eval $(/usr/local/bin/aws ecr get-login --region eu-central-1),應登錄圖像到ECR碼頭註冊表(來源:https://blog.madisonhub.org/gitlab-ci-build-how-to-login-to-ecr/)。

我找不到問題,所以我希望你能幫助我。

預先感謝您。 PS:如果我從本地執行aws ecr get-login的命令,它工作正常。所以它應該不得不對gitlab做些什麼。我是否必須更改允許私人註冊表登錄的某些配置?

回答

2

背景:
你基本上是試圖運行碼頭工人,容器,不可用gitlab-CI默認內的碼頭工人服務器。在gitlab-CI腳本

docker version

:您可以通過運行檢查泊塢窗客戶端和服務器的狀態。這通常是確保客戶機和服務器正常運行的好主意。

運行此碼頭工人服務器沒有運行,這就是爲什麼你得到這個錯誤後,您會發現: Cannot connect to the Docker daemon. Is the docker daemon running on this host?

解決方案:
有幾種方法可以解決你這個問題,因爲在詳細的Gitlab文檔說明如下:
https://docs.gitlab.com/ce/ci/docker/using_docker_build.html

我們解決了它是利用涉及更新Gitlab亞軍配置和使用特殊DO運行構建的docker-in-docker executor方式cker-in-docker(dind)Docker Image

您將需要更新跑步者,使其在特權模式下運行。下面是一個示例config.toml

[[runners]] 
    url = "https://gitlab.com/ci" 
    token = TOKEN 
    executor = "docker" 
    [runners.docker] 
    tls_verify = false 
    image = "docker:latest" 
    privileged = true 
    disable_cache = false 
    volumes = ["/cache"] 
    [runners.cache] 
    Insecure = false 

然後用使用docker:latest圖像和docker:dind服務。下面是一個示例gitlab-ci.yaml片段:

image: docker:latest 

# When using dind, it's wise to use the overlayfs driver for 
# improved performance. 
variables: 
    DOCKER_DRIVER: overlay 

services: 
- docker:dind 

before_script: 
- docker info 

build: 
    stage: build 
    script: 
    - docker version 
    - docker build -t my-docker-image . 
    - docker run my-docker-image /script/to/run/tests 

另一種方法是建立一個獨立的泊塢窗服務器,設置環境變量DOCKER_TLS_VERIFYDOCKER_HOST讓你的搬運工客戶端可以安全地連接到服務器。

要啓用TLS,您需要遵循以下說明:
https://docs.docker.com/engine/security/https/