2016-03-03 69 views
0

我有一個碼頭工人,撰寫文件,看起來像這樣:搬運工,撰寫試圖訪問註冊表V1的第一個「向上」

version: '2' 
services: 
    registry: 
    restart: always 
    image: registry:2 
    ports: 
     - 5000:5000 
    environment: 
     REGISTRY_STORAGE: "s3" 
     REGISTRY_STORAGE_S3_ACCESSKEY: "yada" 
     REGISTRY_STORAGE_S3_SECRETKEY: "yada" 
     REGISTRY_STORAGE_S3_REGION: "us-east-1" 
     REGISTRY_STORAGE_S3_BUCKET: "docker-registry" 
     REGISTRY_STORAGE_S3_ENCRYPT: "true" 
     REGISTRY_STORAGE_S3_SECURE: "true" 
     REGISTRY_STORAGE_S3_V4AUTH: "true" 
     REGISTRY_STORAGE_S3_CHUNKSIZE: "5242880" 
    volumes: 
    - ./data:/data 

prototype: 
    restart: always 
    image: localhost:5000/prototype 
    ports: 
     - 8081:8081 
    volumes: 
     - /opt/config:/config 
    depends_on: 
     - registry 

奇怪的是在撰寫文件試圖從拉第一次運行註冊表v1,而不是v2。第二次運行時,一切正常。我希望「depends_on」能夠防止這種情況發生。我在這裏做錯了什麼?

首先運行:

# docker-compose up 
Starting docker_registry_1 
Recreating docker_prototype_1 
Pulling prototype (localhost:5000/prototype:latest)... 
Pulling repository localhost:5000/prototype 
ERROR: Error while pulling image: Get http://localhost:5000/v1/repositories/prototype/images: read tcp [::1]:35416->[::1]:5000: read: connection reset by peer 

注意在URL中的 「V1」。

第二輪:

# docker-compose up 
docker_registry_1 is up-to-date 
Recreating 9a743a171c84_docker_prototype_1 
Pulling prototype (localhost:5000/prototype:latest)... 
latest: Pulling from prototype 
a3ed95caeb02: Already exists 
3286cdf780ef: Already exists 
...and so on 

回答

0

我相信可能發生的是,註冊表是不是真正準備好服務的時候撰寫請求試圖啓動第二服務。 depends_on只適用於一個訂單,它實際上並不等待以前的服務「準備好」,因爲它無法知道「準備就緒」實際上意味着什麼。

我相信它打到v1網址的原因是因爲docker從v2開始,當它失敗時它會去嘗試v1,並且引發的錯誤是第二次嘗試。

我會建議將這些服務解耦成兩個單獨的撰寫文件。一個運行註冊表,另一個運行依賴註冊表的應用程序。在啓動應用程序之前,您可以運行健康檢查註冊表。

+0

你是絕對正確的,謝謝!對於那些在家中的人,我最終將docker-compose分成了兩個文件,首先啓動註冊表,然後像在Bash腳本中那樣輪詢端點: 'while! (NMAP -Pn -p5000 127.0.0.1 | grep的-q打開) 做 \t printf的 「註冊表還沒有準備好... \ n」 個 睡眠1 做 printf的 「註冊表已經準備好\ n!」' 然後開始微服務 – tcpnewb