问题
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).
回答1:
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
回答2:
You might want to use the -p
flag
Usage:
docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
docker-compose -h|--help
Options:
-f, --file FILE Specify an alternate compose file (default: docker-compose.yml)
-p, --project-name NAME Specify an alternate project name (default: directory name)
来源:https://stackoverflow.com/questions/51563603/docker-compose-how-to-specify-path-to-docker-file-while-building-as-if-in-diffe