Skaffold: Feature request: Allow absolute paths for dockerfile parameter

Created on 29 Mar 2019  ·  10Comments  ·  Source: GoogleContainerTools/skaffold

When specifying the dockerfile parameter in skaffold.yaml, this path seems to be always relative to the Docker build context, even if it starts with /. This is how I understand the docs:
https://skaffold.dev/docs/references/yaml/

Also a short test showed me that is working like this.

But the official -f flag from Docker - which has the same functionality - isn't relative to the Docker build context if it starts with /. Here, the dockerfile can be located elsewhere.

Expected behavior

The build parameter dockerfile should behave like the docker build -f.

Actual behavior

The build parameter dockerfile is always relative to the build context even if it starts with a /. This limits flexibility in some cases.

areconfig kindocumentation kinquestion

Most helpful comment

I just realized, that Skaffold can also use the local docker CLI instead of the docker go library. The docker CLI does not care where the Dockerfile is located, so that you can put your Dockerfile wherever you want. To enable it, change your pipeline config as follows:

apiVersion: skaffold/v1beta7
kind: Config
build:
  artifacts:
  - image: gcr.io/k8s-skaffold/skaffold-example
    docker:
      dockerfile: /wherever/Dockerfile    # Dockerfile outside of the artifact context
  local:
    useDockerCLI: true   # <<<<<

@.maintainers is this a feature that should be documented?

All 10 comments

You are right, the dockerfile needs to be inside the context right now. This is mainly because the docker context needs to be tar'ed and be sent to the builders (which may be in the cloud and not local). Allowing absolute dockerfiles will be intricate. Is there an important use-case you need to address with that?

Btw, the Skaffold code is not fully consistent. For example, when parsing dockerfiles, absolute paths are allowed and passed on (https://github.com/GoogleContainerTools/skaffold/blob/bb5df8a749f5e98eff9c8e2a833efc846c42918b/pkg/skaffold/docker/parse.go#L350). Later, this absolute path will be garbled (https://github.com/GoogleContainerTools/skaffold/blob/bb5df8a749f5e98eff9c8e2a833efc846c42918b/pkg/skaffold/docker/context.go#L37).

Right now, I have all of my Dockerfiles outside of the build context in a central "build" folder. So I have to write a workarround to copy them first into each build context and then build.

Nothing big, but effort. Makes it a bit more complicated for me than building with Docker directly. I would love to build always using Skaffold :-)

I just realized, that Skaffold can also use the local docker CLI instead of the docker go library. The docker CLI does not care where the Dockerfile is located, so that you can put your Dockerfile wherever you want. To enable it, change your pipeline config as follows:

apiVersion: skaffold/v1beta7
kind: Config
build:
  artifacts:
  - image: gcr.io/k8s-skaffold/skaffold-example
    docker:
      dockerfile: /wherever/Dockerfile    # Dockerfile outside of the artifact context
  local:
    useDockerCLI: true   # <<<<<

@.maintainers is this a feature that should be documented?

@corneliusweig that flag is mentioned in https://skaffold.dev/docs/how-tos/builders/ and https://skaffold.dev/docs/references/yaml/, though it's not the most exposed documentation. if you find a place that you think it would fit better feel free and open a PR!

it is a bit of a strange UX to not support absolutely dockerfile paths, but as @corneliusweig said it would be non-trivial to support. @sniederm are you happy with the workaround proposed here?

Oh by "feature" I meant the combination absoluteDockerfile+dockerCLI. I think the doc for useDockerCLI by itself is just fine.

Yes, I think we should mention this in https://skaffold.dev/docs/how-tos/builders/#dockerfile-locally-with-docker

@sniederm - would this solve your problem?

Now I have the copy workaround in place. Havent tried it yet, but the workaround mentioned by you guys looks good to me. Will give feedback as soon as I refactored that part. Thanks!

@sniederm Did you get a chance to try around the steps mentioned in https://github.com/GoogleContainerTools/skaffold/issues/1893#issuecomment-481057140

I am closing this for now. Please feel free to re-open this.

I'm closing this issue as it hasn't seen activity in awhile, and it's unclear if this issue still exists. If this issue does continue to exist in the most recent release of Skaffold, please feel free to add a comment and we'll re-open it.

If someone sees a similar issue, please create a new issue, but do include a link to this issue if possible.

Thank you for opening the issue!

In my use case the solution was:
structure:

├── skaffold.yaml
├── repo_1
 |   ├── service_1.go
     ├── Dockerfile.dev
     └── k8s-service1.yaml
├── repo_2
     ├── service_2.go
     ├── Dockerfile.dev
     ├── libs/foo
     └── k8s-service2.yaml

skaffold.yaml:

artifacts:
    - image: registry_xxx/repo1
      context: .
      docker:
        dockerfile: ./repo1/Dockerfile.dev
  local:
    useBuildkit: true
    push: false
    useDockerCLI: true # use this to allow the dockerfile use

This allow a dockerfile, to take something from Repo2 for example:
Dockerfile.dev:

COPY repo2/libs/foo /code/libs/foo
Was this page helpful?
0 / 5 - 0 ratings