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.

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:

asked Dec 6, 2015 at 17:37

billkw's user avatar

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

czerasz's user avatar

czerasz

14.4k10 gold badges57 silver badges63 bronze badges

answered Dec 6, 2015 at 18:06

Andy Shinn's user avatar

I forgot the first rule of docker: when in doubt, upgrade. $ docker-compose --version docker-compose version: 1.5.1 Too bad the second rule is, prepare to spend the rest of your day fixing what the upgrade broke…

Yep. Docker is a very fast-paced world right now! :)

If you're on a Mac or Windows, make sure you are using Docker Toolbox to keep all of your Docker tools versioned correctly docker.com/docker-toolbox

How to make it work in docker-compose version: 3 ?

@artificerpi is this possible?

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

def test_valid_url_in_build_path(self):
    valid_urls = [
        'git://github.com/docker/docker',
        '[email protected]:docker/docker.git',
        '[email protected]: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@',
)

answered Dec 6, 2015 at 18:08

VonC's user avatar

Comments

Sorry to revive this topic, but it came up as the first link and i could't find any other information elsewhere.

If you want to build from a specific repository tag, you will need to append #tagname such as

build: https://github.com/postgres/pgadmin4.git#REL-6_4

see the docker documentation.

Also building on top of the answer of @philipp-fock. Using the raw file works, as long as the original Dockerfile did not include any other files within that repository (no COPY, ADD)

Using

answered Feb 8, 2022 at 17:18

Hung's user avatar

Comments

I think there is a better way to do this now!

If you want to use a Dockerfile that's located inside the repo and the repo is public, your best guess is to use the raw file.

E.g. for the file Dockerfile_dev inside https://github.com/certbot/certbot, you could use https://raw.githubusercontent.com/certbot/certbot/master/Dockerfile-dev

Then in docker-compose, add it like this in order to use the Dockerfile from the remote location.

certbot_dev:
  image: certbot-dev
  build: https://raw.githubusercontent.com/certbot/certbot/master/Dockerfile-dev

You can find the raw link, when you click on a button called 'Raw' inside the file preview: https://github.com/certbot/certbot/blob/master/Dockerfile-dev

find raw file on github

answered Aug 25, 2021 at 7:01

Philipp Fock's user avatar

This worked for me! But, a question: does it make sense to have image when you also have build? Doesn't the build key effectively make the image key irrelevant (since no prebuilt image will be downloaded, but rather it will be built using the specified Dockerfile)?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.