-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Want a way to specify a dockerfile outside the context in the docker-compose dockerfile directive #4926
Comments
It already works?
|
That's an absolute path. Given that this is checked in to a repo and I don't know where it will be checked out, I can't practically use an absolute path. How would I specify it using a relative path (as I said, I don't care if it is relative to the context or relative to the docker-compose.yml file)? |
Not a Compose issue I'm afraid. |
You are right. I could have sworn that I tested that, but obviously whatever I thought I did wasn't a proper test, because I see that error myself trying it again. |
FWIW it is possible to use a Dockerfile outside the of the build context:
It would be great if docker-compose could support this as well. |
It seems that you can use version: '2'
services:
service:
build:
context: ../path/to/service
dockerfile: $PWD/Dockerfile-for-service |
Docker 18.03 will add support for Dockerfile outside of the context directory; docker/cli#886 @shin- not sure if changes are needed in Docker Compose for that? |
@thaJeztah Thanks! This will require some changes to support it both in the SDK and in Compose, but I'll put it on the list. |
cd ./.. wont work? |
@shin- How is this supposed to work? I'm trying to use:
with the
Trying to build directly from the docker CLI using |
@masaeedu A relative path is not supported. What you can do is to specify a path relative to the current working directory using |
yo yo I have it working as you want, check it out below. I put Dockerfile and docker-compose.yml in a dir called At top level of project make a file called
Don't change anything in your Dockerfile, it's good to go. Now make your compose file like so:
Now at the root of the project, simply run:
Voila! |
Why is a relative path ok for |
The Dockerfile is relative to the context. Dockerfile path does not need to be a relative simply because the relative part of the path is defined in the context. |
This is working |
This is because we build using a Dockerfile outside of the build context, which is supported only in v18+ (docker/compose#4926 (comment)). On Docker 17, you get an error: ``` $ IMAGE=foo cmd/symbols/build.sh /home/sqs/src/github.com/sourcegraph/sourcegraph Compiling the symbols service... Building symbols image foo... unable to prepare context: The Dockerfile (/home/sqs/src/github.com/sourcegraph/sourcegraph/cmd/symbols/Dockerfile) must be within the build context (/tmp/sgdockerbuild_sBc8sv6) ```
I recently came across this issue and your solution was a life saver @colltoaction |
The version: '2'
services:
service:
build:
context: ../path/to/service
dockerfile: ${PWD:-.}/Dockerfile-for-service In this case the dockerfile is resolved to |
|
I've read several discussions about the security reasons why paths outside the context are not permitted. OK, but it seems to me that that should not apply to the dockerfile directive. After all, you can specify a dockerfile outside the context when using the docker build command itself, using -f. I'd like to be able to do the same thing in docker-compose, either relative to the context or relative to the dockerfile-compose.yml file. My goal is to put all the dockerfile-specific config in a subdirectory next to my context directory. I can do that with everything except the dockerfile itself.
The text was updated successfully, but these errors were encountered: