我怎样才能让docker-compose从远程git仓库build立一个映像?

Docker-compose允许您使用预先存在的docker镜像或从源代码构build。 对于构build选项, 官方参考需要

要么是一个包含Dockerfile的目录的path,要么是一个到git仓库的url

我想利用后一种情况,这样我就不必在我的项目中创build一个git子模块,或者在Docker Hub上注册一个新的存储库。 不幸的是,没有关于如何格式化URL的例子,我尝试过的每一个表单都被误认为是一个相对的文件path。

例如

--- letsencrypt: build: https://github.com/letsencrypt/letsencrypt.git ... 

失败的错误:

错误:构buildpath/{MY_CURRENT_PATH}/https:/github.com/letsencrypt/letsencrypt.git不存在或不可访问。

我没有更多的运气与我试过的其他forms:

  • git@github.com:letsencrypt / letsencrypt.git
  • 混帐://github.com/letsencrypt/letsencrypt.git
  • https://github.com/letsencrypt/letsencrypt

你正在运行版本1.5.2? 看起来这实际上是最近添加在https://github.com/docker/compose/pull/2430 。 尝试升级。

例:

 --- version: '2' services: redis: image: "redis:3.2.3" hostname: redis redis-commander: build: https://github.com/joeferner/redis-commander.git command: --redis-host redis links: - "redis:redis" ports: - 8081 

经testing:

 $ docker-compose -v docker-compose version 1.11.2, build dfed245 

文件tests/unit/config/config_test.py显示:

 def test_valid_url_in_build_path(self): valid_urls = [ 'git://github.com/docker/docker', 'git@github.com:docker/docker.git', 'git@bitbucket.org:atlassianlabs/atlassian-docker.git', 'https://github.com/docker/docker.git', 'http://github.com/docker/docker.git', 'github.com/docker/docker.git', ] 

这通过compose/config/config.py#L79-L85

 DOCKER_VALID_URL_PREFIXES = ( 'http://', 'https://', 'git://', 'github.com/', 'git@', )