8

I would like to build a new image in my docker compose project using a git repository as I need to change some ARG vars.

My concern is that the Dockerfile is inside a folder of the git repository.

How can be specified a folder as build context using a git repository?

Repository: https://github.com/wodby/drupal-php/blob/master/7/Dockerfile

version: "2"
services:
  php:
    build:
      context: https://github.com/wodby/drupal-php.git
      dockerfile: 7/Dockerfile
      args:
         - BASE_IMAGE_TAG=7.1
         - WODBY_USER_ID=117
         - WODBY_GROUP_ID=111
      volumes:
          - ./:/var/www/html

I've tried the dockerfile property: "FOLDER/" + Dockerfile

But the repository uses relative paths, and it doesn't find dependencies:

 ---> 6cc2006e9102
Step 7/9 : COPY templates /etc/gotpl/
ERROR: Service 'phpe' failed to build: COPY failed: stat /var/lib/docker/tmp/docker-builder740707850/templates: no such file or directory
jorgetutor
  • 460
  • 1
  • 3
  • 9
  • Could be related: May 2022, see "[Build docker image using different directory contexts](https://stackoverflow.com/a/73084798/6309)": **Dockerfiles now support multiple build contexts**. – VonC Jul 22 '22 at 18:45
  • @VonC Does docker build context from git url also copies git folder in the container ? – power-cut Mar 09 '23 at 04:43
  • @power-cut No, what ends up in the container is only what you ADD or COPY from your Dockerfile. – VonC Mar 09 '23 at 12:21
  • @VonC Can you have a look at this question ? https://stackoverflow.com/questions/75680792/vscode-not-detecting-git-folder-after-build-docker/75681024 – power-cut Mar 09 '23 at 18:56

1 Answers1

16

It should be this way: myrepo.git#:myfolder

version: "2"
services:
  php:
    build:
      context: https://github.com/wodby/drupal-php.git#:7
      args:
         - BASE_IMAGE_TAG=7.1
         - WODBY_USER_ID=117
         - WODBY_GROUP_ID=111
      volumes:
          - ./:/var/www/html

https://docs.docker.com/engine/reference/commandline/build/#git-repositories

jorgetutor
  • 460
  • 1
  • 3
  • 9
  • 4
    For private repositories: Use `https://${TOKEN}:@github.company.com/org/repo.git` with `TOKEN` in _gitignored_ `.env` file to protect the token. Source: [docker-compose-issue-3038](https://github.com/docker/compose/issues/3038#issuecomment-292044389) as mentioned by both @Dorin and @David in [stackoverflow] (https://stackoverflow.com/questions/56458434/host-key-verification-failed-when-building-image-with-docker-compose-from-a-priv), and [docker-compose:environment-variables] (https://docs.docker.com/compose/environment-variables/) – marvin_x Oct 30 '19 at 14:30