HiveBrain v1.2.0
Get Started
← Back to all entries
snippetdockerMinor

How to "docker-compose build" a service from code located in local git repository?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
localdockerlocatedservicecomposegithowcoderepositoryfrom

Problem

I have a git repository placed in local file system at /home/nou/code/lib.git
Also I have /home/nou/docker-compose.yaml that is used to deploy a service based on the code from the repo:

version: '2'
services:
  lib:
    container_name: lib
    build: git://./code/lib.git/
    #build: git://./code/lib.git
    #build: git:///home/nou/code/lib.git/
    #build: git://file:///home/nou/code/lib.git/


As you can see, am trying to build lib service from the local git repo, but the only result I observe is such error (or similar):

nou@ubuntu:~/$ docker-compose build
Building lib
ERROR: error fetching: fatal: unable to connect to .:
.: No address associated with hostname

: exit status 128


How can I use local git repo to build services using docker-compose?

Solution

What you are specifically after (building from a bare repository on a local filesystem) isn't functionality offered by Docker, and by extension, docker-compose. Docker supports building from a few different URLs, but not bare repositories on local filesystems. You can try a few workarounds:

  • Build straight from Github: docker build https://github.com/docker/rootfs.git



  • Run a Git daemon to use the git:// protocol: git daemon --base-path=. --export-all (in /home/nou/code)



  • Running a Git daemon from within Docker, mounting your bare repository as a volume and building inside it via a mounted Docker socket



  • Converting your bare repository to a normal one



https://docs.docker.com/engine/reference/commandline/build/#build-with-url

Context

StackExchange DevOps Q#2217, answer score: 6

Revisions (0)

No revisions yet.