kamal icon indicating copy to clipboard operation
kamal copied to clipboard

Allow setting the Dockerfile and the Docker build context when building

Open calmyournerves opened this issue 2 years ago • 0 comments

Hey there 👋

We're using a monorepo and gems get included in the apps via path (e.g. gem 'mygem', path: '../mygem'). As Docker limits everything to the context (default .), including gems outside of the context does not work. I'm no Docker expert, but setting the context to .. and specifying the Dockerfile with --file Dockerfile seems to do the trick.

This PR:

  • adds a context option to the builder config
  • adds a dockerfile option to the builder config The default value for this is Dockerfile and it will always be appended to the build command. This is helpful if someone wants to use different Dockerfiles (e.g. Dockerfile.development). I'm not sure if this is feasible as a config option at all, but to support passing the context, the --file argument seems to be needed in the build command (and maybe is a little more explicit). Otherwise, Docker would look for the Dockerfile in the root of the context.

The build configuration would look as follows:

# Set context
builder:
  context: ".."

# Use different Dockerfile
builder:
  dockerfile: Dockerfile.xyz

# Set context and Dockerfile
builder:
  context: ".."
  dockerfile: "../Dockerfile.xyz" # Dockerfile is in the parent directory

It would also be possible to just allow configuring the context and making sure the --file Dockerfile argument always gets passed to the build command (without it being a configuration option).

calmyournerves avatar Mar 04 '23 10:03 calmyournerves