syntaqx
syntaqx

Reputation: 2876

Building a heroku docker image for a specific context

When using heroku.yml developer preview (https://devcenter.heroku.com/articles/build-docker-images-heroku-yml). Is there currently any way of specifying a docker build context as well as the dockerfile?

The command I'd like to emulate is:

docker build -f cmd/api/Dockerfile .

Note: I provide the path . for the build context here.

Currently, I'm able to successfully run the following:

build:
  docker:
    web: cmd/api/Dockerfile

Or, using the more explicit version:

build:
  docker:
    web:
      dockerfile: cmd/api/Dockerfile

Based on the ability to target a stage from a multi-stage build, my assumption was that I would also be able to provide context in the same way I would docker-compose as a field for the build:

build:
  docker:
    web:
      dockerfile: cmd/api/Dockerfile
      context: .

However, this returns the following error response from Heroku:

remote: Building source:
remote: === Fetching app code
remote:
remote: =!= There were problems parsing your heroku.yml. We've detected the following issues:
remote:
remote: build.docker.web.context in body is a forbidden property
remote: Verifying deploy...
remote:
remote: !       Push rejected to docker-build-context-test.
remote:

Is this a known feature that I can implement? It's very possible I might need to send in a feature request, as this functionality is a developer preview, but it feels like something they would've included.

Hope you guys have some answers!

Upvotes: 4

Views: 2161

Answers (2)

Jean Claveau
Jean Claveau

Reputation: 1471

As a workaround, using a symbolic link to your Dockerfile works:

ln -s  path/to/your/Dockerfile Dockerfile.heroku

with

build:
  docker:
    web:
      dockerfile: Dockerfile.heroku

Upvotes: 1

thisismydesign
thisismydesign

Reputation: 25162

https://devcenter.heroku.com/articles/build-docker-images-heroku-yml

The Docker build context is always set to the directory containing the Dockerfile and cannot be configured independently.

Upvotes: 5

Related Questions