terraform-provider-docker
terraform-provider-docker copied to clipboard
Inconsistent Behavior with Docker Image Build Context in Terraform
trafficstars
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and docker Provider) Version
Terraform v1.9.8
on linux_amd64
Affected Resource(s)
docker_image
Terraform Configuration Files
# Working Configuration
resource "docker_image" "scsb_fastapi" {
name = "hsiangjenli/scsb-fastapi:${local.current_date}"
build {
context = "."
dockerfile = "/home/hsiangjenli/Downloads/github/refactor-fastapi/Dockerfile.fastapi"
build_args = {
FASTAPI_MODULE_PATH = "TODO"
PREPROCESSING_MODULE_PATH = "TODO"
}
no_cache = "true"
}
}
# Non-working Configuration
resource "docker_image" "scsb_fastapi" {
name = "hsiangjenli/scsb-fastapi:${local.current_date}"
build {
context = "/home/hsiangjenli/Downloads/github"
dockerfile = "refactor-fastapi/Dockerfile.fastapi"
build_args = {
FASTAPI_MODULE_PATH = "TODO"
PREPROCESSING_MODULE_PATH = "TODO"
}
no_cache = "true"
}
}
Actual Behaviour
The second configuration throws the following error:
Error: failed to read dockerfile: unexpected EOF
with docker_image.scsb_fastapi,
on main.tf line 13, in resource "docker_image" "scsb_fastapi":
13: resource "docker_image" "scsb_fastapi" {
Steps to Reproduce
- Apply the first configuration with
terraform apply, which works correctly. - Modify the configuration to the second setup (changing the context path) and run
terraform applyagain, which results in the "unexpected EOF" error.
Important Factoids
The reason for using the second configuration is to include additional modules from different paths into the Docker image. I’m trying to specify a different context directory for this purpose, but I’m unsure why the second configuration fails while the first works fine.