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
4
  • Could be related: May 2022, see "Build docker image using different directory contexts": Dockerfiles now support multiple build contexts. Commented Jul 22, 2022 at 18:45
  • @VonC Does docker build context from git url also copies git folder in the container ? Commented Mar 9, 2023 at 4:43
  • @power-cut No, what ends up in the container is only what you ADD or COPY from your Dockerfile. Commented Mar 9, 2023 at 12:21
  • @VonC Can you have a look at this question ? stackoverflow.com/questions/75680792/… Commented Mar 9, 2023 at 18:56

1 Answer 1

17

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

Sign up to request clarification or add additional context in comments.

1 Comment

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 as mentioned by both @Dorin and @David in [stackoverflow] (stackoverflow.com/questions/56458434/…), and [docker-compose:environment-variables] (docs.docker.com/compose/environment-variables)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.