Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker Compose: How to specify path to docker file while building as if in different directory?

docker build -t test2 -f tests/low_conviction_integration/Dockerfile .

If I need to copy a file from a directory ABOVE my Dockerfile, I can accomplish it by calling

docker build -t image_name -f path_to_docker_file/Dockerfile .

from that ABOVE directory

How can I accomplish the same behavior with docker-compose? I want docker-compose to exist in same directory as Dockerfile, to build with Dockerfile, but to ultimately call it as if it was in ABOVE directory, so that I can copy the correct file. I tried

docker-compose -f path_to_docker_file_and_compose/docker-compose.yml up

from ABOVE directory, but when building from the Dockefile, it complains the files in ABOVE directory are not there to copy when building (which means it is running the docker build from the same directory as the Dockerfile. I need it to run the build from the ABOVE directory).

like image 482
docker_man Avatar asked Jul 27 '18 18:07

docker_man


1 Answers

This can be done like this, add build in docker-compose.yml and run the build from ABOVE directory:

version: '3.8'

services:
  your_service:
    build: # "context" and "dockerfile" fields have to be under "build"
      context: .
      dockerfile: <Below_Directory>/Dockerfile
like image 128
Sumit Avatar answered Oct 18 '22 18:10

Sumit