How can I make docker-compose build an image from a remote git repository?

Docker-compose allows you to utilize either preƫxisting docker images or build from source. For the build option, the official reference requires

Either a path to a directory containing a Dockerfile, or a url to a git repository.

  • File locks support in Docker volumes of NFS4 shares
  • How to reach additional containers by the hostname after docker-compose scale?
  • Docker-compose container ports not working
  • Upgrade docker-compose to version 3
  • How can I diagnose issue with Oracle Data Pump import failing with error 1089
  • Can docker be used to run a web site container that first downloads latest version prior to running web server?
  • I’d like to take advantage of the latter case, so that I don’t have to create a git submodule in my project, or register a new repository on Docker Hub. Unfortunately, there are no examples for how to format the url, and every form I’ve tried is mistaken for a relative file path.

    e.g.

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

    Fails with the error:

    ERROR: build path /{MY_CURRENT_PATH}/https:/github.com/letsencrypt/letsencrypt.git either does not exist or is not accessible.

    I didn’t have any more luck with the other forms I’ve tried:

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

  • Using docker bridge network IP to access vhost in apache container
  • Cannot Start Django in Docker
  • Docker receiving multicast traffic
  • Swarm node Status down, but node should be Ready
  • How can I configure an index pattern?
  • Force a problematic docker container to restart itself?
  • 2 Solutions collect form web for “How can I make docker-compose build an image from a remote git repository?”

    Are you running version 1.5.2? It looks like this was actually recently added in https://github.com/docker/compose/pull/2430. Try upgrading.

    Example:

    ---
    
    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
    

    Tested with:

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

    The file tests/unit/config/config_test.py shows:

    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',
        ]
    

    This is confirmed with compose/config/config.py#L79-L85:

    DOCKER_VALID_URL_PREFIXES = (
        'http://',
        'https://',
        'git://',
        'github.com/',
        'git@',
    )
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.